Sometimes we need functions for building or modifying arrays whose elements are to be references to other variables (arrays or objects for instance). In this example, I wrote two functions 'tst' and 'tst1' that perform this task. Note how the functions are written, and how they are used.
<?php
function tst(&$arr, $r) {
array_push($arr, &$r);
}
$arr0 = array(); $arr1 = array(1,2,3); tst($arr0, &$arr1); print_r($arr0); array_push($arr0, 5); array_push($arr1, 18); print_r($arr1);
print_r($arr0); function tst1(&$arr, &$r) {
array_push($arr, &$r);
}
$arr0 = array(); $arr1 = array(1,2,3); tst1($arr0, $arr1); echo "-------- 2nd. alternative ------------ <br>\n";
print_r($arr0); array_push($arr0, 5); array_push($arr1, 18);
print_r($arr1);
print_r($arr0); ?>
In both cases we get the same result.
I hope this is somehow useful
Sergio.