note 116617 deleted from control-structures.foreach by salathe
| From: | salathe@php.net | Date: | Fri, 06 Feb 2015 13:33:45 +0000 |
| Subject: | note 116617 deleted from control-structures.foreach by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-201637@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
When passing a function to foreach, the function is only called once and not on every loop.
<?php
function get_array(){
static $c = 0;
$c ++;
return array($c, $c);
}
foreach(get_array() as $item){
echo $item.PHP_EOL;
}
?>
Will output:
1 1