Re: ${}
| From: | Robert Cummings | Date: | Wed, 25 Apr 2007 13:41:45 +0000 |
| Subject: | Re: ${} | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-253702@lists.php.net to get a copy of this message | ||
On Wed, 2007-04-25 at 21:23 +0800, Man-wai Chang wrote:
> where can I find the documentation about this "symbol"?
Maybe in the documentation? A cursory glance from me though didn't turn
anything up. Either way I can inform you of the purpose...
The following two expression have the same result:
$foo = 5;
${'foo'} = 5;
The difference being that the code between { and } is first evaluated to
determine the name of the variable. $foo is preferred and faster but
there may be the odd time when you find doing something like the
following useful:
${'foo_'.$i} = $someValue;
So let's imagine $i = 3, then a variable called $foo_3 has been created
and can even be accessed as $foo_3.
If you are familiar with variable variables then you may be aware that
the above can also be achieved as follows:
$name = 'foo_'.$i;
$$name = $someValue;
Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com
|
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'