note 116617 added to control-structures.foreach

From: Date: Thu, 29 Jan 2015 20:41:48 +0000
Subject: note 116617 added to control-structures.foreach
Groups: php.notes 
Request: Send a blank email to php-notes+get-201556@lists.php.net to get a copy of this message
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 ---- Server IP: 72.52.91.14 Probable Submitter: 96.21.107.169 ---- Manual Page -- http://php.net/manual/en/control-structures.foreach.php Edit -- https://master.php.net/note/edit/116617 Del: integrated -- https://master.php.net/note/delete/116617/integrated Del: useless -- https://master.php.net/note/delete/116617/useless Del: bad code -- https://master.php.net/note/delete/116617/bad+code Del: spam -- https://master.php.net/note/delete/116617/spam Del: non-english -- https://master.php.net/note/delete/116617/non-english Del: in docs -- https://master.php.net/note/delete/116617/in+docs Del: other reasons-- https://master.php.net/note/delete/116617 Reject -- https://master.php.net/note/reject/116617 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#201556) next »