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

 ID:                 54616
 Updated by:         ras...@php.net
 Reported by:        kozo at alphanet dot ro
 Summary:            in_array return true if the haystack contain 0
-Status:             Open
+Status:             Bogus
 Type:               Bug
 Package:            Unknown/Other Function
 Operating System:   win, linux
 PHP Version:        5.2.17
 Block user comment: N
 Private report:     N

 New Comment:

That's what the 3rd param to the in_array() call is for. 

You are looking for a string in an array of integers. 

(int)'something' == 0 and 0 exists in the array. If you

want a strict check that does a type check as well, set

the strict flag. No bug here.


Previous Comments:
------------------------------------------------------------------------
[2011-04-27 23:45:25] kozo at alphanet dot ro

Description:
------------
The in_array function return true if the haystack have an element with
value 0

Test script:
---------------
if (in_array('something', array(0)) ) {

        echo 'something is in array';

} else {

        echo 'something is NOT in array';

}





if (in_array('something', array(0, 'element1', 'element2')) ) {

        echo 'something is in array';

} else {

        echo 'something is NOT in array';

}



Expected result:
----------------
something is NOT in array

Actual result:
--------------
something is in array


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



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

Reply via email to