note 107506 added to control-structures.foreach
| From: | Anonymous | Date: | Tue, 14 Feb 2012 07:01:52 +0000 |
| Subject: | note 107506 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-186118@lists.php.net to get a copy of this message | ||
Regarding [John 17-May-2010 04:38]; making your value "by-reference" {prepending
"&" to $val in foreach()} will give you the desired result:
<?php
$arr = array(1,2,3,4,5);
foreach($arr as &$val) if($val==3) $arr[]=6; else echo $val;
?>
will show "12456" (as desired) not "1245" (as would get if referenced
"by-value").
----
Server IP: 69.147.83.197
Probable Submitter: 72.219.151.91
----
Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php
Edit -- https://master.php.net/note/edit/107506
Del: integrated -- https://master.php.net/note/delete/107506/integrated
Del: useless -- https://master.php.net/note/delete/107506/useless
Del: bad code -- https://master.php.net/note/delete/107506/bad+code
Del: spam -- https://master.php.net/note/delete/107506/spam
Del: non-english -- https://master.php.net/note/delete/107506/non-english
Del: in docs -- https://master.php.net/note/delete/107506/in+docs
Del: other reasons-- https://master.php.net/note/delete/107506
Reject -- https://master.php.net/note/reject/107506
Search -- https://master.php.net/manage/user-notes.php