Current Location: Home> Function Categories> array_replace

array_replace

Replace elements of the first array with the passed array
Name:array_replace
Category:Array
Programming Language:php
One-line Description:Replace the value of the first array with the value of the following array.

Definition and usage

array_replace() function replaces the value of the first array with the value of the following array.

Tip: You can pass an array, or multiple arrays to the function.

If a key exists in the first array array1 and also in the second array2 , the value in the first array array1 will be replaced by the value in the second array array2 . If a key exists only in the first array array1 , it will remain unchanged. (See Example 1 below for details)

If a key exists in the second array array2 but does not exist in the first array array1 , this element is created in the first array array1 . (See Example 2 below for details)

If multiple replacement arrays are passed, they will be processed in sequence, and the values ​​of the subsequent array will overwrite the values ​​of the previous array. (See Example 3 below for details)

Tip: Please use array_replace_recursive() to recursively replace the value of the first array with the value of the following array.

grammar

 array_replace ( array1 , array2 , array3 ... )
parameter describe
array1 Required. Specify array.
array2 Optional. Specifies an array to replace the value of array1 .
array3 ,... Optional. Specifies multiple arrays to replace values ​​of array1 and array2 , .... The value of the subsequent array will overwrite the value of the previous array.
Similar Functions
Popular Articles