On Thu, 15 Feb 2007 15:52:28 +0100, TMN <na******@gmail.comwrote:
I would like to append stuff to an array but doing it by reference -
this is not working - can anyone help ?
$anArray[]= "";
$ref = &$anArray[];
$ref = "a";
$ref = "b";
$ref = "c";
anArray now contains a,b and c
This cannot be done like that. $anArray[] is not 'the mystical place where
variables go to be added to an array'. It's a construct that appends
something as a last item to an array, and any reference to it will result
in the actual value added at that point, not a 'new' array value.
Just use $anArray[] = 'foo';, or possibly:
$mainArray = array('foo' =bar,'foz'= array());
$anArray = &$mainArray['foz'];
$anArray[] = 'foo';
$anArray[] = 'bar';
Or even the array_push()/array_unshift() functions.
What is the actual problem you're trying to solve here?
--
Rik Wasmus