In PHP,
null==0
0=="0"
If you combine these two, you would expect:
null=="0"
But this is not true.
Could someone explain this to me?
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.
You have to understand that because PHP is not strict in its typing it is often casting your variables to other types depending on the comparison or operation needed. In the case of null==0 it is telling you that both null and integer 0 are considered false.
In the case of null == “0” it is checking if the string “0” is empty which it is not. Comparing integer 0 with string “0” type cases “0” to an int for comparison in which case they are equal.
Hope that helps.