Re: dynamically naming PHP vars on the fly?

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

 



On Wed, 5 Aug 2009 16:17:26 -0600, Govinda wrote:

> I want to do this:
> (I am just assuming it won't work; I haven't even tried it yet)
> 
> $var1='apple';
> $Fruit_$var1="organic";
> echo "$Fruit_apple"; // I want this to return "organic"
> 
> Or how are you guys dynamically naming PHP vars on the fly?

Others have mentioned variable variables. While I have
used those, I tend to prefer arrays:

  $var1 = 'apple';
  $fruits[$var1] = 'organic';
  echo $fruits[$var1];


/Nisse

-- 
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