+ 4

[PHP] What does string 'false' evaluates?

Answer: boolean true. How? Can you give me example please? Here I tried: https://code.sololearn.com/wKAYAZ5G41oH/?ref=app

28th Apr 2018, 12:35 PM
Kawalpreet Juneja
Kawalpreet Juneja - avatar
4 Answers
+ 3
Converting to a boolean causes all values to be evaluated to true except: * the boolean FALSE itself * the integer 0 (zero)the float 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 empty tags Obtained from http://php.net/manual/en/language.types.boolean.php Try writing $x = '0', and the result will be false. Also notice something random like: $x = 'The sun is warm101', will result in true.
28th Apr 2018, 1:45 PM
Rrestoring faith
Rrestoring faith - avatar
+ 2
When you write 'false' or 'true' those are strings not the boolean values true and false. And in PHP I believe non-empty strings are evaluated to be the boolean value true. That is why you were getting those results.
28th Apr 2018, 1:40 PM
cyk
cyk - avatar
+ 2
Oh. Got it cyk Rrestoring faith. Thanks a lot :)
28th Apr 2018, 3:08 PM
Kawalpreet Juneja
Kawalpreet Juneja - avatar
+ 1
Come on! Whoever downvoted this atleast should have posted the reason! If you think this question is wrong, look where I found this question: https://s.amsu.ng/KpaJ9l5xeTrN
28th Apr 2018, 12:46 PM
Kawalpreet Juneja
Kawalpreet Juneja - avatar