php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23626 in_array and array_search stop at value 0
Submitted: 2003-05-14 06:23 UTC Modified: 2003-05-14 21:08 UTC
From: jjkola at email dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4CVS-2003-05-14 (stable) OS: Win2000
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jjkola at email dot com
New email:
PHP Version: OS:

 

 [2003-05-14 06:23 UTC] jjkola at email dot com
Hi!

I think I found a bug. I had a array where one of the values were zero and I tried to search with in_array and later also with array_search if there is a string for example "-". I expected them to tell me if the string is in array, but the result was always same wether or not there was searched string and it was that they gave me answer true when checking with in_array and when checking with array_search it gave me location of that zero value. Here is a sample code snippet the fiddle with:

<?php
$test=array(0,"*",1,"+",2);
if (in_array("-",$test)) print"string bug!\n";
if (in_array("abc",$test)) print"string bug!\n";
$test=array(1,"*",0,"+",2);
if (array_search("-",$test)) {
  print "string buugie!\n";
  $value=array_search("-",$test);
  print "Value is $value.";
}
?>

I tried it with longer strings and it behaved same way as told above. I checked also with other types of variables as a needle but they worked fine.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-14 06:31 UTC] edink@php.net
See the manual entry for in_array (3rd argument).
 [2003-05-14 12:25 UTC] jjkola at email dot com
Yes, I know that strict-parameter, but I still think this isn't how it should behave. In my opinion it shouldn't stop going through the array when it finds zero and especially because it's telling misleading information. Now I'm forced to use that strict-parameter to make it behave in right and predictable way.
 [2003-05-14 13:03 UTC] sniper@php.net
There is not bug. (documented behaviour)


 [2003-05-14 13:24 UTC] jjkola at email dot com
May I know where that information is located? I didn't see it in manual (chm-version, May 11 2003). 

in_array:

"Searches haystack for needle and returns TRUE if it is found in the array, FALSE otherwise."
And there is also mention about that strict-parameter

array_search:

"Searches haystack for needle and returns the key if it is found in the array, FALSE otherwise"

"This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE, such as 0 or ""."
 [2003-05-14 14:33 UTC] jjkola at email dot com
Sorry, for still setting this open but I would like to know where that information is located.
 [2003-05-14 21:08 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

http://www.php.net/manual/en/function.in-array.php

Read the online docs :)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 10:01:29 2024 UTC