note 97945 added to control-structures.foreach

From: Date: Mon, 17 May 2010 23:38:18 +0000
Subject: note 97945 added to control-structures.foreach
Groups: php.notes 
Request: Send a blank email to php-notes+get-169333@lists.php.net to get a copy of this message
For those wishing to try the heresy of adding to an array while it is being processed in a foreach loop, note that your added value will not be processed at the end of the loop! $arr = array(1,2,3,4,5); foreach($arr as $val) if($val==3) $arr[]=6; else echo $val; will show "1245" not "12456". ---- Server IP: 66.207.199.35 Probable Submitter: 174.7.33.239 ---- Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php Edit -- https://master.php.net/note/edit/97945 Del: integrated -- https://master.php.net/note/delete/97945/integrated Del: useless -- https://master.php.net/note/delete/97945/useless Del: bad code -- https://master.php.net/note/delete/97945/bad+code Del: spam -- https://master.php.net/note/delete/97945/spam Del: non-english -- https://master.php.net/note/delete/97945/non-english Del: in docs -- https://master.php.net/note/delete/97945/in+docs Del: other reasons-- https://master.php.net/note/delete/97945 Reject -- https://master.php.net/note/reject/97945 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#169333) next »