note 97945 deleted from control-structures.foreach by googleguy
| From: | googleguy@php.net | Date: | Wed, 14 Nov 2012 22:26:40 +0000 |
| Subject: | note 97945 deleted from control-structures.foreach by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-191958@lists.php.net to get a copy of this message | ||
Note Submitter: John
----
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!
<?php
$arr = array(1,2,3,4,5);
foreach($arr as $val) if($val==3) $arr[]=6; else echo $val;
?>
will show "1245" not "12456".