<?php
for ($i=0; $i<count($big_array); $i++){
//
}
?>
Having this approach, program will try to count the $big_array every time it loops and it may cause some performance issues. To make it more efficient, we should code it this way:
<?php
for ($i=0, $n=count($big_array); $i<$n; $i++){
//
}
?>
It does the counting during initialization only.
4 comments:
even faster and less memory consuming should be:
reset($big_array);
while ( list($key, $value) = each($big_array) ) {
//
}
I really loved read this blog. It has lot of information’s to the public. Thanks for sharing this information in internet
nice information,
thank you.
Nice post regarding array used in PHP.
Post a Comment