|
Posted by Rik on 02/15/07 15:06
On Thu, 15 Feb 2007 15:52:28 +0100, TMN <nash.rsa@gmail.com> wrote:
> I would like to append stuff to an array but doing it by reference -
> this is not working - can anyone help ?
>
> $anArray[]=3D "";
>
> $ref =3D &$anArray[];
>
> $ref =3D "a";
> $ref =3D "b";
> $ref =3D "c";
>
> anArray now contains a,b and c
This cannot be done like that. $anArray[] is not 'the mystical place whe=
re =
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 resul=
t =
in the actual value added at that point, not a 'new' array value.
Just use $anArray[] =3D 'foo';, or possibly:
$mainArray =3D array('foo' =3D> bar,'foz'=3D array());
$anArray =3D &$mainArray['foz'];
$anArray[] =3D 'foo';
$anArray[] =3D 'bar';
Or even the array_push()/array_unshift() functions.
What is the actual problem you're trying to solve here?
-- =
Rik Wasmus
Navigation:
[Reply to this message]
|