#23626 [Opn->Bgs]: in_array and array_search stop at value 0

From: Date: Wed, 14 May 2003 18:03:05 +0000
Subject: #23626 [Opn->Bgs]: in_array and array_search stop at value 0
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-39656@lists.php.net to get a copy of this message
 ID:               23626
 Updated by:       sniper@php.net
 Reported By:      jjkola at email dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Arrays related
 Operating System: Win2000
 PHP Version:      4CVS-2003-05-14 (stable)
 New Comment:

There is not bug. (documented behaviour)




Previous Comments:
------------------------------------------------------------------------

[2003-05-14 12:25:41] 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 06:31:33] edink@php.net

See the manual entry for in_array (3rd argument).

------------------------------------------------------------------------

[2003-05-14 06:23:15] 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.

------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=23626&edit=1



Thread (7 messages)

« previous php.bugs (#39656) next »