You are here: Re: Arrays and references « PHP Programming Language « IT news, forums, messages
Re: Arrays and references

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация