note 10012 deleted from language.references.whatdo by sniper
| From: | sniper@php.net | Date: | Tue, 30 Sep 2003 01:20:02 +0000 |
| Subject: | note 10012 deleted from language.references.whatdo by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-57324@lists.php.net to get a copy of this message | ||
Note Submitter: brichardson@lineone.net
----
Be careful with references and arrays. If $array contains the key "red" with the value
"apple" then this code:
$tmp =& $array["red"];
echo $tmp;
will give the ouput apple. But if there is no such key in the array, then the above code will NOT
ONLY leave $tmp unset (as you would expect) BUT ALSO create the key "red" with an unset
value (which you might not expect).
To be clearer, this code:
unset($array);
$tmp =& $array["red"];
reset($array);
echo key($array)."<Br>";
$tmp = "apple";
echo $array["red"]."<Br>";
will give this output:
red
apple