note 82653 added to function.count

From: Date: Sun, 20 Apr 2008 23:57:35 +0000
Subject: note 82653 added to function.count
Groups: php.notes 
Request: Send a blank email to php-notes+get-138589@lists.php.net to get a copy of this message
In response to yarolan at mail dot ru: I actually find Duff's Device to be particularly useful in the example put forth by yarolan. He wrote: $arr_size=count($arr); for($i=0;$i<$arr_size;$i++) { ... } If the order of processing doesn't matter, I do this: $i = count($some_array); while ($i--): do_something_to($some_array[$i]); endwhile; If it does matter, I like this: $i = count($some_array); $some_array = array_reverse($some_array); while ($i--): do_something_to($some_array[$i]); endwhile; I have no idea if it's faster as I haven't tested it. Mostly, I just like the way it looks. ;) To email me, find me on TheHolierGrail.com or MacNimble.com ---- Server IP: 69.147.83.197 Probable Submitter: 72.192.51.154 ---- Manual Page -- http://www.php.net/manual/en/function.count.php Edit -- https://master.php.net/note/edit/82653 Del: integrated -- https://master.php.net/note/delete/82653/integrated Del: useless -- https://master.php.net/note/delete/82653/useless Del: bad code -- https://master.php.net/note/delete/82653/bad+code Del: spam -- https://master.php.net/note/delete/82653/spam Del: non-english -- https://master.php.net/note/delete/82653/non-english Del: in docs -- https://master.php.net/note/delete/82653/in+docs Del: other reasons-- https://master.php.net/note/delete/82653 Reject -- https://master.php.net/note/reject/82653 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#138589) next »