note 10012 modified in What References Do by ronabop

From: Date: Sun, 10 Dec 2000 03:35:57 +0000
Subject: note 10012 modified in What References Do by ronabop
Groups: php.notes 
Request: Send a blank email to php-notes+get-8558@lists.php.net to get a copy of this message
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 http://www.php.net/manual/what-references-do.php

« previous php.notes (#8558) next »