note 88093 added to function.count

From: Date: Fri, 09 Jan 2009 22:55:55 +0000
Subject: note 88093 added to function.count
Groups: php.notes 
Request: Send a blank email to php-notes+get-149001@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... Shouldn't the lines finish with a $i++ instead of a i++ ? If I'm correct, that should be : for ($i = 0; $i < count($arr)-1; $i++) { Nico. ---- Server IP: 89.31.146.176 Probable Submitter: 82.233.199.196 ---- Manual Page -- http://www.php.net/manual/en/function.count.php Edit -- https://master.php.net/note/edit/88093 Del: integrated -- https://master.php.net/note/delete/88093/integrated Del: useless -- https://master.php.net/note/delete/88093/useless Del: bad code -- https://master.php.net/note/delete/88093/bad+code Del: spam -- https://master.php.net/note/delete/88093/spam Del: non-english -- https://master.php.net/note/delete/88093/non-english Del: in docs -- https://master.php.net/note/delete/88093/in+docs Del: other reasons-- https://master.php.net/note/delete/88093 Reject -- https://master.php.net/note/reject/88093 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#149001) next »