Re: A question about associative arrays
| From: | Dan Hardiker | Date: | Fri, 13 Sep 2002 16:32:43 +0000 |
| Subject: | Re: A question about associative arrays | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-116293@lists.php.net to get a copy of this message | ||
> I understand that (and why)..
> $arr[key] is bad
> $arr['key'] is good
>
> but; what about
> $arr[$key]
>
> should it be
> $arr["$key"]
To know this you have to know how PHP parses. The $ sign denotes a
variable name, and at run time this is converted into the variable value.
For example:
$var = "test";
$var2 = $var;
That is the "correct" way to do it, not
$var2 = "$var";
(even though it will work) for the same reasoning, $arr[$key] should be used.
All "$var" does, is evaluate the variable and make it a string... causes
more work for the parser than is needed.
--
Dan Hardiker [dhardiker@staff.firstcreative.net]
ADAM Software & Systems Engineer
First Creative Ltd