note 86296 added to function.count

From: Date: Sat, 11 Oct 2008 12:53:01 +0000
Subject: note 86296 added to function.count
Groups: php.notes 
Request: Send a blank email to php-notes+get-145274@lists.php.net to get a copy of this message
redbehelit at yahoo dot com wrote: ----------------------------------------------- for ($i = 0; $i < count($arr); i++) { This loop is going to try to traverse to $arr[26] which does not exist. The last element is at index number 25. We can fix this with a minor edit: for ($i = 0; $i < count($arr)-1; i++) { ------------------------------------------------ That is incorrect. Even if count IS 26 it won't traverse it because you arre using the < operator. Think about it : 26 is NOT less than 26... ---- Server IP: 69.147.83.197 Probable Submitter: 81.76.49.11 ---- Manual Page -- http://www.php.net/manual/en/function.count.php Edit -- https://master.php.net/note/edit/86296 Del: integrated -- https://master.php.net/note/delete/86296/integrated Del: useless -- https://master.php.net/note/delete/86296/useless Del: bad code -- https://master.php.net/note/delete/86296/bad+code Del: spam -- https://master.php.net/note/delete/86296/spam Del: non-english -- https://master.php.net/note/delete/86296/non-english Del: in docs -- https://master.php.net/note/delete/86296/in+docs Del: other reasons-- https://master.php.net/note/delete/86296 Reject -- https://master.php.net/note/reject/86296 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#145274) next »