Saturday, September 19, 2009

More foreach optimization

Suppose you key value array and your using foreach i have done one more optimization.
I am using while loop.
$array = array('first'=>'max','second'=>'pain');
foreach($array $key=>$value)
{
print 'Key: ' . $key . ' Value: ' . $value ;
}

=====Optimized Code=====
while(list($key,$value)=each($array))
{
print 'Key: ' . $key . ' Value: ' . $value ;
}
=====Optimized Code=====
The while loop runs more faster then foreach.

No comments:

Post a Comment