PHP array_replace_recursive() Function
Last Updated : 17 Mar 2025
The array_replace_recursive() function is an inbuilt function of PHP. The array_replace_recursive( ) function is used to replace the values from passed arrays into the first array recursively. This function was introduced in PHP 5.3.0.
Syntax
Parameter
| Parameter | Description | Is compulsory |
|---|---|---|
| array1 | Specifies an array. | compulsory |
| array2 | Specifies an array which will replace the values of array1. | Optional |
| array3,... | Specifies more arrays to replace the values of array1 and array2, etc. values from later arrays will overwrite the previous ones. | Optional |
Return type
The array_replace_recursive( ) function returns the replaced array. It will return null if an error occurs.
Example 1
Output:
Array
(
[a] => Array
(
[0] => all
)
[b] => Array
(
[0] => black
)
)
Example 2
Output:
Array
(
[a] => Array
(
[0] => saffron
)
[b] => Array
(
[0] => pink
[1] => red
)
)
Example 3
Output:
Array
(
[a] => Array
(
[0] => yuvraj
)
[b] => Array
(
[0] => ishant
[1] => sehwag
)
)
Example 4
Output:
Array
(
[a] => Array
(
[0] => Perl
)
[b] => Array
(
[0] => HTML
[1] => PHP
)
)
Next TopicPhp-array-reset-function