Php array replace recursive
From w3cyberlearnings
Contents |
PHP function array_replace_recursive
This function manipulates an array by replacing the replacement array into the base array recursively.
Syntax array_replace_recursive
- base: origional array
- replacement: replacement array
array_replace_recursive(base, replacement);
Note
This function is for PHP 5 >= 5.3.0.
Example 1
<?php $base = array('dog'=>array('lolo',29),'cat'=>array(29)); $replacements = array('dog'=>'dodo','cat'=>array('mark',13)); $basket = array_replace_recursive($base, $replacements); print_r($basket); ?>
Output
Array ( [dog] => dodo [cat] => Array ( [0] => mark [1] => 13 ) )
Example 2
<?php $base = array(3=>'bob',4=>'john'); $replacements = array(4=>'dodo',3=>array('mark',13)); $basket = array_replace_recursive($base, $replacements); print_r($basket); ?>
Output
Array ( [3] => Array ( [0] => mark [1] => 13 ) [4] => dodo )
Related Links
- array_change_key_case
- array_chunk
- array_combine
- array_count_values
- array_diff_assoc
- array_diff_key
- array_diff_uassoc
- array_diff_ukey
- array_diff
- array_fill_keys
- array_fill
- array_filter
- array_flip
- array_intersect_assoc
- array_intersect_key
- array_intersect_uassoc
- array_intersect_ukey
- array_intersect
- array_key_ exists
- array_keys