note 100132 added to function.count
| From: | K3fka at osu1 dot php dot net | Date: | Mon, 27 Sep 2010 17:21:48 +0000 |
| Subject: | note 100132 added to function.count | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-172740@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 69.147.83.197
Probable Submitter: 168.213.1.132
----
Manual Page -- http://www.php.net/manual/en/function.count.php
Edit -- https://master.php.net/note/edit/100132
Del: integrated -- https://master.php.net/note/delete/100132/integrated
Del: useless -- https://master.php.net/note/delete/100132/useless
Del: bad code -- https://master.php.net/note/delete/100132/bad+code
Del: spam -- https://master.php.net/note/delete/100132/spam
Del: non-english -- https://master.php.net/note/delete/100132/non-english
Del: in docs -- https://master.php.net/note/delete/100132/in+docs
Del: other reasons-- https://master.php.net/note/delete/100132
Reject -- https://master.php.net/note/reject/100132
Search -- https://master.php.net/manage/user-notes.php