asi Posted January 30, 2022 Share Posted January 30, 2022 I have wired code: PHP 8.1.2 if (in_array('false', [true], false)) { return true; } Above code return true ;/ why? Above code is equivalent to: if ('false' == true) { return true; } http://sandbox.onlinephpfunctions.com/code/6f6e1f06d145d74f71d2dc5fa08f36ef5dcda6ee Quote Link to comment https://forums.phpfreaks.com/topic/314485-in_array/ Share on other sites More sharing options...
Barand Posted January 30, 2022 Share Posted January 30, 2022 'false' is a string value, not a boolean false. From the PHP manual... Quote When converting to bool, the following values are considered false: the boolean false itself the integer 0 (zero) the floats 0.0 and -0.0 (zero) the empty string, and the string "0" an array with zero elements the special type NULL (including unset variables) SimpleXML objects created from attributeless empty elements, i.e. elements which have neither children nor attributes. Every other value is considered true (including any resource and NAN). 1 Quote Link to comment https://forums.phpfreaks.com/topic/314485-in_array/#findComment-1593755 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.