|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-01-14 00:57 UTC] christopher dot r dot haley at gmail dot com
Description: ------------ --- From manual page: http://www.php.net/function.in-array --- From phpinfo(), the version is: 5.5.9-1ubuntu4.5 but that was not a choice in the drop down. It seems to span over other versions as well. Test script: --------------- $arr = array("a" => 0); echo intval(in_array("b", $arr)); Expected result: ---------------- Expected output is 0 (false) when the first argument is not present in second argument. Actual result: -------------- Output is 1 (true) regardless of the first argument. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Fri Jan 16 00:00:01 2026 UTC |
> Wow, I never knew [a string] == 0. Non-numeric strings. To compare, PHP converts the string to a number (as opposed to converting the number to a string), and since "b" is non-numeric it converts to 0. $arr = array("a" => 123); echo intval(in_array("123", $arr)); // 1 echo intval(in_array("123", $arr, true)); // 0chrisevans07a, as the responder said 4 years ago, it's a loose comparison. To compare a string to a number, PHP converts the string to a number. To compare a string to a boolean, PHP converts a string to a boolean. See below: var_dump("a" == 0); // true var_dump("1" == 0); // false var_dump("a" == false); // false var_dump("0" == false); // true