note 110761 deleted from control-structures.foreach by googleguy
| From: | googleguy@php.net | Date: | Mon, 03 Dec 2012 23:40:10 +0000 |
| Subject: | note 110761 deleted from control-structures.foreach by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-192266@lists.php.net to get a copy of this message | ||
Note Submitter: henke at henke37 dot cjb dot net
----
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.