note 88093 deleted from function.count by danbrown

From: Date: Fri, 09 Jan 2009 22:57:20 +0000
Subject: note 88093 deleted from function.count by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-149002@lists.php.net to get a copy of this message
Note Submitter: niconux ---- > 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.

« previous php.notes (#149002) next »