array_replace Replaces elements from passed arrays into the first array &reftitle.description; arrayarray_replace arrayarray arrayreplacements array_replace creates a new array and assigns items into it for each key in each of the provided arrays. If a key appears in multiple input arrays, the value from the right-most input array will be used. array_replace does not process elements items recursively, it replaces the entire value for each key when it does a replacement. &reftitle.parameters; array The array in which elements are replaced. replacements Arrays from which elements will be extracted. Values from later arrays overwrite the previous values. &reftitle.returnvalues; Returns an array. &reftitle.examples; <function>array_replace</function> example "pineapple", 4 => "cherry"); $replacements2 = array(0 => "grape"); $basket = array_replace($base, $replacements, $replacements2); var_dump($basket); ?> ]]> &example.outputs; string(5) "grape" [1]=> string(6) "banana" [2]=> string(5) "apple" [3]=> string(9) "raspberry" [4]=> string(6) "cherry" } ]]> Example of how nested arrays are handled [ 'orange', 'lemon' ], 'pome' => [ 'apple' ] ]; $replacements = [ 'citrus' => [ 'grapefruit' ] ]; $replacements2 = [ 'citrus' => [ 'kumquat', 'citron' ], 'pome' => [ 'loquat' ] ]; $basket = array_replace($base, $replacements, $replacements2); var_dump($basket); ?> ]]> &example.outputs; array(2) { [0]=> string(7) "kumquat" [1]=> string(6) "citron" } ["pome"]=> array(1) { [0]=> string(6) "loquat" } } ]]> &reftitle.seealso; array_replace_recursive array_merge