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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
17 - 11 = ?
Subscribe to this entry?

 
 [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 Oct 31 23:01:28 2024 UTC