List Info

Thread: note 68494 added to function.each




note 68494 added to function.each
user name
2006-07-29 20:02:15
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.p
hp.net/note/edit/68494
Del: integrated  -- ht
tp://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://m
aster.php.net/note/delete/68494/spam
Del: non-english -- h
ttp://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://ma
ster.php.net/manage/user-notes.php

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )