note 107506 deleted from control-structures.foreach by danbrown

From: Date: Thu, 10 May 2012 20:55:03 +0000
Subject: note 107506 deleted from control-structures.foreach by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-187847@lists.php.net to get a copy of this message
Note Submitter: Anonymous ---- 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").

« previous php.notes (#187847) next »