note 110761 added to control-structures.foreach
| From: | henke at henke37 dot cjb dot net | Date: | Mon, 03 Dec 2012 22:49:18 +0000 |
| Subject: | note 110761 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-192265@lists.php.net to get a copy of this message | ||
Another example on the array copy semantics:
<?php
$arr=array( 0=>"NO",1=>"YES",2=>"MAYBE");
foreach($arr as $k=>$v) {
$arr[$k+1]="SURE";
echo "$v\n<br>";
}
echo '<hr>';
foreach($arr as $k=>$v) {
echo "$v\n<br>";
}
?>
This would be a "modify while iterating" situation if the copy wasn't made. And those
are bad.
----
Server IP: 80.67.0.53
Probable Submitter: 90.230.202.243
----
Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php
Edit -- https://master.php.net/note/edit/110761
Del: integrated -- https://master.php.net/note/delete/110761/integrated
Del: useless -- https://master.php.net/note/delete/110761/useless
Del: bad code -- https://master.php.net/note/delete/110761/bad+code
Del: spam -- https://master.php.net/note/delete/110761/spam
Del: non-english -- https://master.php.net/note/delete/110761/non-english
Del: in docs -- https://master.php.net/note/delete/110761/in+docs
Del: other reasons-- https://master.php.net/note/delete/110761
Reject -- https://master.php.net/note/reject/110761
Search -- https://master.php.net/manage/user-notes.php