Re: Dynamically assigning var namesi

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, August 1, 2006 12:49 pm, bob pilly wrote:
> Does anyone know if you can assign a new variable name based on the
> contents of another variable in PHP? If so whats the syntax to do
> this?

You can and it's called Variable Variables in the documentation...

99% of the time, it's better to use an array.

>  I am parsing a text file that has tens of preset attributes and some
> of these have hundreds of sub attributes. For example the text file
> contains flight details, on every flight there can be up to 500
> passengers but there are generally only 50 so i dont want to have
> declare 500 vars when i hardly ever use them. What i am trying to do
> is count the amount of pasengers present and dynamically create the
> variables based on this.$surname1,$surname2 etc...
>
>  Im not sure whether this is a sane way to approach this problem or
> not. Any advice or pointing to relevant documentation about either
> syntax for this or ways of tackling this sort of problem (im sure it
> must be a regular occurance in the coding world??) would be greatly
> appreciated!!

In this case, it's DEFINITELY better to use an array, as it is almost
guaranteed that sooner or later you will have a flight with two people
named "John Smith" on it.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux