Php array replace
From w3cyberlearnings
Contents |
PHP function array_replace
This function replaces array from the replacement array into the origional array.
Syntax array_replace
- base: origional array
- replacement: replacement array
array_replace(base, replacement,..);
Note
This function available in PHP 5 >= 5.3.0
Example 1
<?php $base = array('apple', 'banana', 'orange'); $replace = array('APPLE_app', 'BANANA_app', 'ORANGE_app'); $new_a= array_replace($base,$replace); print_r($new_a); ?>
Output
Array ( [0] => APPLE_app [1] => BANANA_app [2] => ORANGE_app )
Example 2
<?php $base = array('apple','orange','banana','coconut'); $replace1 = array(0=>'dog',1=>'cat',2=>'tiger'); $new_aa = array_replace($base, $replace1); print_r($new_aa); ?>
Output
Array ( [0] => dog [1] => cat [2] => tiger [3] => coconut )
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