note 98810 added to control-structures.foreach
| From: | g_adams27 at hotmail dot com | Date: | Thu, 08 Jul 2010 22:19:42 +0000 |
| Subject: | note 98810 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170805@lists.php.net to get a copy of this message | ||
Regarding John's comment (17-May-2010) about adding to an array while it is being processed, he
is correct - you will have to use "each" to accomplish that.
# This prints 1245, not 12456.
$arr = array(1,2,3,4,5);
foreach($arr as $val) if($val==3) $arr[]=6; else echo $val;
# This DOES print 12456
$arr = array(1,2,3,4,5);
while(list(,$val) = each($arr)) if($val==3) $arr[]=6; else echo $val;
----
Server IP: 64.71.164.2
Probable Submitter: 64.102.249.6
----
Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php
Edit -- https://master.php.net/note/edit/98810
Del: integrated -- https://master.php.net/note/delete/98810/integrated
Del: useless -- https://master.php.net/note/delete/98810/useless
Del: bad code -- https://master.php.net/note/delete/98810/bad+code
Del: spam -- https://master.php.net/note/delete/98810/spam
Del: non-english -- https://master.php.net/note/delete/98810/non-english
Del: in docs -- https://master.php.net/note/delete/98810/in+docs
Del: other reasons-- https://master.php.net/note/delete/98810
Reject -- https://master.php.net/note/reject/98810
Search -- https://master.php.net/manage/user-notes.php