note 111808 added to control-structures.foreach
| From: | fornah at mail dot ru | Date: | Sat, 30 Mar 2013 13:52:42 +0000 |
| Subject: | note 111808 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-194275@lists.php.net to get a copy of this message | ||
Note that if you pass some function that returns an array to iterate it, that function would call
just once:
<?php
$i = 0;
function arr()
{
global $i;
$i++;
return array('1', '2', '3', '4', $i);
}
foreach (arr() as $k => $v)
echo '['. $k .'] = '. $v ."\n";
/*
[0] = 1
[1] = 2
[2] = 3
[3] = 4
[4] = 1
but not
[0] = 1
[1] = 2
[2] = 3
[3] = 4
[4] = 5
*/
?>
----
Server IP: 69.147.83.199
Probable Submitter: 213.151.8.2
----
Manual Page -- http://php.net/manual/en/control-structures.foreach.php
Edit -- https://master.php.net/note/edit/111808
Del: integrated -- https://master.php.net/note/delete/111808/integrated
Del: useless -- https://master.php.net/note/delete/111808/useless
Del: bad code -- https://master.php.net/note/delete/111808/bad+code
Del: spam -- https://master.php.net/note/delete/111808/spam
Del: non-english -- https://master.php.net/note/delete/111808/non-english
Del: in docs -- https://master.php.net/note/delete/111808/in+docs
Del: other reasons-- https://master.php.net/note/delete/111808
Reject -- https://master.php.net/note/reject/111808
Search -- https://master.php.net/manage/user-notes.php