Skip to content
Advertisement

array replace function not working for me

is there any array replace function in php ..

in php manual there is a function called array_replace but its not working…

Tell me some example…

for array replace..

Advertisement

Answer

<?php
$base = array("orange", "banana", "apple", "raspberry");
$replacements = array(0 => "pineapple", 4 => "cherry");
$replacements2 = array(0 => "grape");

$basket = array_replace($base, $replacements, $replacements2);
echo '<pre>' .
print_r($base, true) .
print_r($basket, true) .
'</pre>';

output

Array
(
    [0] => orange
    [1] => banana
    [2] => apple
    [3] => raspberry
)
Array
(
    [0] => grape
    [1] => banana
    [2] => apple
    [3] => raspberry
    [4] => cherry
)

the question is: what exactly isnt working for you?

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement