note 100132 deleted from function.count by danbrown
| From: | danbrown@php.net | Date: | Mon, 27 Sep 2010 17:24:10 +0000 |
| Subject: | note 100132 deleted from function.count by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-172741@lists.php.net to get a copy of this message | ||
Note Submitter: K3fka
----
Adding on to what yarolan down there said, one can do this to avoid calculating the length of an
array on each cycle of a for loop:
<?php
for ($i = 0, $arr_length = count($array); $i <= $arr_length; $i++)
?>
This will assign the value of count($array) to the variable $arr_length when it gives the value of 0
to $i, so it will only have to run count() that one time at the beginning of the loop.