Jump to: navigation, search

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


Navigation
Web
SQL
MISC
References