note 16725 added to language.types.string
| From: | suapboy at i dot com dot ua | Date: | Sat, 10 Nov 2001 12:52:44 +0000 |
| Subject: | note 16725 added to language.types.string | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-20660@lists.php.net to get a copy of this message | ||
There is a funny thing... I had something like this:
$a = array("lala" => 10, "zuzu" => 20);
define('KUKU', 'lala'); //name of a key in the array
And I tried to print some value of the array:
echo KUKU." is $a[KUKU]";
And php didn't print the value, just:
lala is
It was a big problem until I understood that it was the same as if I wrote:
echo KUKU." is ".$a["KUKU"];
Don't forget about that. The right ways to do it were:
echo KUKU." is ".$a[KUKU]; //ouput: lala is 10
//or
echo KUKU." is ${a[KUKU]}"; //ouput: lala is 10
//or
echo KUKU." is {$a[KUKU]}"; //ouput: lala is 10
//but not
echo KUKU." is $a{[KUKU]}"; //ouput: Array{[KUKU]}
//and not
echo KUKU." is $a[{KUKU}]"; //ouput: Parse error . . .
I think the first one is the most evident and the best for reading.
--
http://www.php.net/manual/en/language.types.string.php
http://master.php.net/manage/user-notes.php?action=edit+16725
http://master.php.net/manage/user-notes.php?action=delete+16725
http://master.php.net/manage/user-notes.php?action=reject+16725