note 60094 deleted from control-structures.foreach by danbrown
| From: | danbrown@php.net | Date: | Tue, 28 Apr 2009 13:07:19 +0000 |
| Subject: | note 60094 deleted from control-structures.foreach by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153916@lists.php.net to get a copy of this message | ||
Note Submitter: pinheirosp at hotmail dot com
----
In reply to FatalError, if you use Zend Dev Studio, i'll notice it's report
"while(list() = each())" calls as "Using While w/ arrays param". So far,
it's may be ambiguous to make things like that.
Prefer to make a clean code and use PHP "kernel" functions to navigate through an array.
Btw, if we take the exec time as example:
//a litte array, just to test =-]
$arr = array();
for($i=0; $i<100000; $i++) $arr[$i] = $i;
//list-each solution
$myTime = microtime(true);
reset($arr);
while (list($key, $value) = each($arr)) {
$value = ($key * $value);
}
$myTime = microtime(true) - $myTime;
echo("list-each : " . $myTime . "<BR />\n");
//foreach solution
$myTime = microtime(true);
foreach ($arr as $key => $value) {
$value = ($key * $value);
}
$myTime = microtime(true) - $myTime;
echo("foreach : " . $myTime . "<BR />\n");
/*
output:
list-each : 0.40198588371277
foreach : 0.23317384719849
*/