note 111808 deleted from control-structures.foreach by aharvey
| From: | aharvey@php.net | Date: | Thu, 04 Apr 2013 03:36:28 +0000 |
| Subject: | note 111808 deleted from control-structures.foreach by aharvey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-194316@lists.php.net to get a copy of this message | ||
Note Submitter: fornah at mail dot ru
----
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
*/
?>