The PHP.net function signature for array_replace () says the arrays will be passed by reference. What would be the reason (s) / benefit in doing it this way, and not by value, since in order to get the intended result you have to return the finished array to the variable. To be clear, I can reproduce the results in the manual, so it is not a question of how to use this function.
Here is the function signature and example, as from php.net.
Source: http://ca3.php.net/manual/en/function.array-replace.php
Functional Signature:
array array_replace ( array &$array , array &$array1 [, array &$... ] )
Code example:
$base = array("orange", "banana", "apple", "raspberry");
$replacements = array(0 => "pineapple", 4 => "cherry");
$replacements2 = array(0 => "grape");
$basket = array_replace($base, $replacements, $replacements2);
print_r($basket);
The above example outputs:
Array
(
[0] => grape
[1] => banana
[2] => apple
[3] => raspberry
[4] => cherry
)
source
share