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
 [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

Pull Requests

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 Dec 26 11:01:30 2024 UTC