php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #11159 array_search() returns false even if a match is made in the first array element
Submitted: 2001-05-28 21:03 UTC Modified: 2001-05-28 22:02 UTC
From: code at samsmail dot com Assigned:
Status: Closed Package: *Function Specific
PHP Version: 4.0.5 OS: Windows 98 SE
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.
Password:
Status:
Package:
Bug Type:
Summary:
From: code at samsmail dot com
New email:
PHP Version: OS:

 

 [2001-05-28 21:03 UTC] code at samsmail dot com
=========START======================
<?php
$arr=array("stuff","thing","doodah","wotsit","here","and","there");
if(array_search("thing",$arr,false)){	/*will not return false here, as expected*/
	print("\"thing\" was found!<br />\n");
}
else{
	print("\"thing\" was <b>not</b> found!<br />\n");
}
print("<hr />\n");
if(array_search("stuff",$arr,false)){	/*will return false despite "stuff" being present in the array*/
	print("\"stuff\" was found!<br />\n");
}
else{
	print("\"stuff\" was <b>not</b> found!<br />\n");
}
?>
=======END=============

Running standard PHP binary distribution on PWS (4.0).

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-05-28 22:02 UTC] sniper@php.net
Yes, the first item's key in array is 0.
Your script's logic is faulty. 

"array_search --  Searches the array for a given value and returns the corresponding key if successful"

--Jani

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 16 09:01:32 2024 UTC