php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6153 count() function not returning proper value
Submitted: 2000-08-14 15:28 UTC Modified: 2000-08-14 15:36 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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jdoyon at nrcan dot gc dot ca
New email:
PHP Version: OS:

 

 [2000-08-14 15:28 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).

Here is the code that gave up the problem :

<?
$keywords = $HTTP_POST_VARS["keywords"];
$lang = $HTTP_POST_VARS["lang"];
$prov = $HTTP_POST_VARS["prov"];

preg_match("/\w+/",$keywords,$words);

$dbm = dbmopen("search_index.db","r");

$recs = array();

for ( $i = 0 ; $i < count($words) ; $i++ ) {
        if ( dbmexists($dbm,$words[$i]) ) {
                $recs = dbmfetch($dbm,$words[$i]);
                $recar = split("-",$recs);
                for ( $ii = 0 ; $ii < count($recar) ; $ii++ ) {
                        $counter[$recar[$ii]]++;
                }
        }
}

for ( $i = 0 ; $i < 1000 ; $i++ ) {
        echo $i." : ".$counter[$i]."<BR>";
}

?>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-08-14 15:36 UTC] zak@php.net
Duplicate
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 00:01:36 2025 UTC