php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6152 count() function not returning proper value
Submitted: 2000-08-14 15:26 UTC Modified: 2000-08-14 15:34 UTC
From: jdoyon at nrcan dot gc dot ca Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0.15 OS: Linux RedHat 6.2
Private report: No CVE-ID: None
 [2000-08-14 15:26 UTC] jdoyon at nrcan dot gc dot ca
I just discovered that the count() function to return the length of an array does not seem to be returning the proper value.

I have an array of length 858, and it keeps telling me it's 464 !

If I manually force the loop I can output all elements, whereas if I use a for() loop with "$i < count($array)" as I usually do, I get only part of it !

I suspect this maybe caused by the fact that this is an array of counters, where not all single elements might get initialized.
(i.e. some counters increase, some remain NULL).

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-08-14 15:34 UTC] zak@php.net
This is not a bug - this is the way that php handles arrays.

PHP considers all arrays to be associative arrays.

For example:
$array[9] = 1;
$array[2] = 1;

count ($array) will return a value of two, even though the last element in the array looks like it is positioned at the 10th numeric index in the array.

Since indexes 0 and 1, and 3 to 8 are not set, then they are not counted.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 21 04:01:35 2024 UTC