note 78535 deleted from function.count by danbrown

From: Date: Fri, 09 Jan 2009 22:59:26 +0000
Subject: note 78535 deleted from function.count by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-149009@lists.php.net to get a copy of this message
Note Submitter: redbehelit at yahoo dot com ---- Be careful if you're using count in a loop. Example: $arr ends at index number 25 (or $arr[25]) We know there are actually 26 elements when we include element 0 (as we should). This is what count is going to return back. But if we do this: 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++) {

« previous php.notes (#149009) next »