|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-09-09 10:04 UTC] marek at lewczuk dot com
Description:
------------
When you have an array with boolean values, then in_array will always return true.
Reproduce code:
---------------
print in_array("test it", array(true, true, "sdsd" => true))
Expected result:
----------------
should return false
Actual result:
--------------
true
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 08:00:01 2025 UTC |
Right, it works with 3rd parameter, but it is not the point - is string "test" equal to boolean "true" ? Even if we are not comparing variable types, then "test" is not equal to "1". For example, I have an array with strings, integers, boolean - I'm looking for any "123" value - I don't care if this is an integer or string - the value is important. In this case, I can't use in_array with 3rd parameter, because it will not find all all correct values. examples: in_array('232', array(232, '232', true)) this will return true - correct in_array('232', array(232, true), true) this will return false - correct in_array('232', array(233, '233', true)) this will return true - wrong In my opinion this is not correct behavior...