if you run this code:
if ( 0=='undefined') echo 'true'; else echo 'false';
you get ‘true’ which means int 0 equals the string ‘undefined’.
Why is that? what am I missing here?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This table documents that when comparing
0and"undefined", both are converted to numbers first. And this section says that"undefined"converts to the number0:So the results of the comparison are expected, if somewhat surprising for someone new to PHP.
If you want the comparison to return
falsebecause the two operands are not of the same type, PHP provides the identical operator===that does exactly this.