note 68494 added to function.each

From: Date: Sat, 29 Jul 2006 20:02:15 +0000
Subject: note 68494 added to function.each
Groups: php.notes 
Request: Send a blank email to php-notes+get-115331@lists.php.net to get a copy of this message
Something that I found useful to note is that each() does NOT return a reference to the array contets, but a copy of the item. So, say you have: $boxes = Array(); $boxes["Large"] = Array(); $boxes["Medium"] = Array(); $boxes["Small"] = Array(); and want to put the small box inside the medium box inside the large box, doing: $lastBox = NULL; while (list($key, $box) = each($boxes)) { if (isset($lastBox)) $lastBox[0] =& $box; $lastBox =& $box; } will not work. Instead, you have to use the key like: $lastBox = NULL; while (list($key) = each($boxes)) { $box =& $boxes[$key]; if (isset($lastBox)) $lastBox[0] =& $box; $lastBox =& $box; } which will work. ---- Server IP: 66.207.199.35 Probable Submitter: 142.167.29.117 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.each.php Edit -- http://master.php.net/note/edit/68494 Del: integrated -- http://master.php.net/note/delete/68494/integrated Del: useless -- http://master.php.net/note/delete/68494/useless Del: bad code -- http://master.php.net/note/delete/68494/bad+code Del: spam -- http://master.php.net/note/delete/68494/spam Del: non-english -- http://master.php.net/note/delete/68494/non-english Del: in docs -- http://master.php.net/note/delete/68494/in+docs Del: other reasons-- http://master.php.net/note/delete/68494 Reject -- http://master.php.net/note/reject/68494 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#115331) next »