note 80157 deleted from function.count by felipe

From: Date: Thu, 03 Jan 2008 18:36:11 +0000
Subject: note 80157 deleted from function.count by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-134720@lists.php.net to get a copy of this message
Note Submitter: zdenek dot wagner at gmail dot com ---- Remember that count() returns the number of elements, not the highest index. Try: $arr[0]=1; $arr[4]=4; printf("<p>count=%d</p>", count($arr)); You see that the count() function finds 2 elements. With the for-loop you will try to access nonexistent $arr[0] and you will never get to $arr[4]. The foreach loop will correctly access $arr[0] and $arr[4].

« previous php.notes (#134720) next »