note 80157 added to function.count

From: Date: Tue, 01 Jan 2008 17:41:52 +0000
Subject: note 80157 added to function.count
Groups: php.notes 
Request: Send a blank email to php-notes+get-134646@lists.php.net to get a copy of this message
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]. ---- Server IP: 212.24.129.51 Probable Submitter: 85.207.70.236 ---- Manual Page -- http://www.php.net/manual/en/function.count.php Edit -- https://master.php.net/note/edit/80157 Del: integrated -- https://master.php.net/note/delete/80157/integrated Del: useless -- https://master.php.net/note/delete/80157/useless Del: bad code -- https://master.php.net/note/delete/80157/bad+code Del: spam -- https://master.php.net/note/delete/80157/spam Del: non-english -- https://master.php.net/note/delete/80157/non-english Del: in docs -- https://master.php.net/note/delete/80157/in+docs Del: other reasons-- https://master.php.net/note/delete/80157 Reject -- https://master.php.net/note/reject/80157 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#134646) next »