php an array of reference
I have two arrays. one will be added with arrays as children, another one keeps references to the array being added to the first one.
$list=array();
$stack=array();
in a for loop:
$list[]=array('something');
$stack[]=& end($list); //errors: Only variables should be as开发者_开发百科signed by reference
what am i doing wrong here? thanks for help.
Edited
$stack[] = &$list[count($list)-1]; //> Assuming numeric index incremental
or
end($list);
$stack[] = &$list[key($list)];
Objects will be always passed by reference in PHP 5.
EDITED
But if array is not a class then
$element = array();
$list[] = &$element;
$stack[] = &$element;
精彩评论