Definition
The array_replace_recursive() function replaces the values of the first array with the values from following arrays recursively.
Syntax
array_replace_recursive(array1, array2, array3, ...)
Parameters
Parameter | Description |
---|---|
array1 |
Required. Specifies an array. |
array2 |
Optional. Specifies an array which will replace the values of array1. |
array3... |
Optional. Specifies more arrays to replace the values of array1 and array2, etc. Values from later arrays will overwrite the previous ones. |
Example
<?php
// Example 1
$ages = array("Mark" => array(22), "Jeff" => array(32), "Mike" => array(28));
$ages2 = array("Mark" => array(23), "Jeff" => array(21), "Mike" => array(18));
print_r(array_replace_recursive($ages, $ages2));
echo "<br>";
// Example 2
$ages = array("Mark" => array(22), "Jeff" => array(32), "Mike" => array(28, 90));
$ages2 = array("Mark" => array(23), "Jeff" => array(21), "Mike" => array(18));
print_r(array_replace_recursive($ages, $ages2));
echo "<br>";