Re: Hashes in strings
| From: | Dan Hardiker | Date: | Thu, 01 Jan 1970 00:00:00 +0000 |
| Subject: | Re: Hashes in strings | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-95703@lists.php.net to get a copy of this message | ||
Hi,
> I would suggest not to use $hash[var1][var2] instead of
> $hash['var1']['var2'] because afaik php will think u mean two constants
> ( var1 and var2 ).
> Just if it doesnt find these constants it will use them as
> $hash['var1']['var2'].
Thats correct, php will think they are constants and upon not finding them
will send up a low priority error (I think its of E_NOTICE). Appologies for
sloppy coding (must remember to be more awake).
$hash['var1']['var2'] is much better, safer, more compatable and faster
(marginally - as it doesnt have to check for constants of that name). As an
extra note, (and this of personal desire rather than coding standards), I
would always break out of a string to insert variables. Personally it just
highlights the dynamic parts of string creation.
eg: = "Name: ".$user->name." is age ".$user->age.". ".(($user-
>birthday==$today)?"Happy Birthday!")."<br />";
but thats getting out of the scope of the question heh
--
Dan Hardiker [dhardiker@staff.firstcreative.net]
ADAM Software & Systems Engineer
First Creative Ltd