note 79261 added to control-structures.foreach
| From: | benny-wegner at gmx dot de | Date: | Sun, 18 Nov 2007 13:36:53 +0000 |
| Subject: | note 79261 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-132380@lists.php.net to get a copy of this message | ||
just discovered a possibility using foreach for iterating ob the original array instead of making a
copy:
function &wrap(&$a) {
return $a;
}
$myArray = array(1, 2, 3);
foreach (test($myArrav) as $myValue) {
echo $myValue ." ";
// testing the operation on reference by changing $myArray
if ($myValue == 3) $myArray []= 4;
}
prints out:
1 2 3 4
----
Server IP: 69.147.83.197
Probable Submitter: 87.170.164.233
----
Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php
Edit -- https://master.php.net/note/edit/79261
Del: integrated -- https://master.php.net/note/delete/79261/integrated
Del: useless -- https://master.php.net/note/delete/79261/useless
Del: bad code -- https://master.php.net/note/delete/79261/bad+code
Del: spam -- https://master.php.net/note/delete/79261/spam
Del: non-english -- https://master.php.net/note/delete/79261/non-english
Del: in docs -- https://master.php.net/note/delete/79261/in+docs
Del: other reasons-- https://master.php.net/note/delete/79261
Reject -- https://master.php.net/note/reject/79261
Search -- https://master.php.net/manage/user-notes.php