I stumbled on a very strange bit of PHP code. Can anyone explain why this is happening? ***** Bonus Points ***** If you can tell me why this is useful.
& lt ;? Php if (0 == 'a') {Print ord (0). "Should never be equal" .ord ('a') "& Lt; br & gt;"; } If (false == 0) {print "false == 0
"; } If ('a' == wrong) {print "a == wrong
"; }? & Gt; and the resulting output:
48 should never be equal to 9 97 == 0 In PHP, 'a' is not ASCII character, but string a In a numerical context, this is equal to 0. For example, the value of intval ('a') is returned in the value of 0 .
This is useful because PHP is mainly used for text processing, and may want to test any test (123 == '123'), which is true. And given that in the singular (or double) quotation marks, a number is considered as a number, it is not a number for the string, whose numeric value is not considered as anything other than 0.
Oh, yes, one more thing. 'A' is true in Boolean context, I do not believe it makes some type of text processing more natural, but I can not honestly think of an example in this late time.
Comments
Post a Comment