배열 함수 목록
PHP Manual

array_replace

(PHP 5 >= 5.3.0)

array_replaceReplaces elements from passed arrays into the first array

설명

array array_replace ( array &$array , array &$array1 [, array &$array2 [, array &$... ]] )

array_replace() replaces the values of the first array with the same values from all the following arrays. If a key from the first array exists in the second array, its value will be replaced by the value from the second array. If the key exists in the second array, and not the first, it will be created in the first array. If a key only exists in the first array, it will be left as is. If several arrays are passed for replacement, they will be processed in order, the later arrays overwriting the previous values.

array_replace() is not recursive : it will replace values in the first array by whatever type is in the second array.

인수

array

The array in which elements are replaced.

array1

The array from which elements will be extracted.

반환값

Returns an array, or NULL if an error occurs.

예제

Example #1 array_replace() example

<?php
$base 
= array("orange""banana""apple""raspberry");
$replacements = array(=> "pineapple"=> "cherry");
$replacements2 = array(=> "grape");

$basket array_replace($base$replacements$replacements2);
print_r($basket);
?>

위 예제의 출력:

Array
(
    [0] => grape
    [1] => banana
    [2] => apple
    [3] => raspberry
    [4] => cherry
)

참고


배열 함수 목록
PHP Manual