|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21055 array_search skips element 0
Submitted: 2002-12-16 16:42 UTC Modified: 2002-12-16 16:50 UTC
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: trees at ieeecs dot ece dot utexas dot edu Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.3.0RC3 OS: Linux RH 7.3
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: trees at ieeecs dot ece dot utexas dot edu
New email:
PHP Version: OS:


 [2002-12-16 16:42 UTC] trees at ieeecs dot ece dot utexas dot edu
(My system info at bottom)

The following piece of code doesn't work as advertised:

 while ( $cur = mysql_fetch_row( $result ))
	if ( ! array_search( $cur[0], $userIDs ))
	    print("Pushing $cur[0]");
	    array_push( $userIDs, $cur[0] );
	  print( "Ignoring $cur[0]", "/tmp/pushing");

My Solution:
I wrote my own little search method (ignoring Big-Oh consisderations since I don't know PHP low-level types)

function my_array_search( $findMe, $inMe ){
  foreach ( $inMe as $key )
    if ( $key == $findMe )
      return true;

  return false;

Relevant system info from phpinfo();

Linux myHostName 2.4.18-18.7.xsmp #1 SMP Wed Nov 13 19:01:42 EST 2002 i686

 './configure' '--with-mysql' '--enable-calendar' '--with-apxs=/usr/sbin/apxs' '--with-bz2' '--with-curl' '--enable-track-vars' '--enable-trans-sid' '--with-imap=/usr/local/lib' '--with-imap-ssl=/lib' '--enable-debug'



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-12-16 16:44 UTC] trees at ieeecs dot ece dot utexas dot edu
print( "Ignoring $cur[0]", "/tmp/pushing");
should be
print( "Ignoring $cur[0]" );

storeOutput is my method for sending output debugging to files.
 [2002-12-16 16:50 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

array_search() returns \"0\" when it finds a match at the first element. Use array_search(...) !== false instead.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Feb 03 01:03:42 2023 UTC