note 93105 added to function.end

From: Date: Mon, 24 Aug 2009 00:05:29 +0000
Subject: note 93105 added to function.end
Groups: php.notes 
Request: Send a blank email to php-notes+get-159817@lists.php.net to get a copy of this message
Take note that end() does not recursively set your multiple dimension arrays' pointer to the end. Take a look at the following: <?php // create the array for testing $a = array(); $i = 0; while($i++ < 3){ $a[] = array(dechex(crc32(mt_rand())),dechex(crc32('lol'.mt_rand()))); } // show the array tree echo '<pre>';var_dump($a); // set the pointer of $a to the end end($a); // get the current element of $a var_dump(current($a)); // get the current element of the current element of $a var_dump(current(current($a))); ?> You will notice that you probably get something like this: array(3) { [0]=> array(2) { [0]=> string(8) "764d8d20" [1]=> string(8) "85ee186d" } [1]=> array(2) { [0]=> string(8) "c8c72466" [1]=> string(8) "a0fdccb2" } [2]=> array(2) { [0]=> string(8) "3463a31b" [1]=> string(8) "589f6b63" } } array(2) { [0]=> string(8) "3463a31b" [1]=> string(8) "589f6b63" } string(8) "3463a31b" The array elements' pointer are still at the first one as current. So do take note. ---- Server IP: 69.147.83.197 Probable Submitter: 218.186.8.248 (proxied: 116.88.224.201) ---- Manual Page -- http://www.php.net/manual/en/function.end.php Edit -- https://master.php.net/note/edit/93105 Del: integrated -- https://master.php.net/note/delete/93105/integrated Del: useless -- https://master.php.net/note/delete/93105/useless Del: bad code -- https://master.php.net/note/delete/93105/bad+code Del: spam -- https://master.php.net/note/delete/93105/spam Del: non-english -- https://master.php.net/note/delete/93105/non-english Del: in docs -- https://master.php.net/note/delete/93105/in+docs Del: other reasons-- https://master.php.net/note/delete/93105 Reject -- https://master.php.net/note/reject/93105 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#159817) next »