why (0 == 'empty') is true in php?-ThrowExceptions

Exception or error:

when I try to execute this condition

if ($status == 'empty') { doSomething(); }
else { echo $status; }

every number as status will echo $status correctly

but when $status = 0 the code won’t work as I expect

so I do some tests and here is the result:

print_r(0 == 'empty'); // return 1
print_r(intval(0) == 'empty'); // return 1
print_r(0 == null) // return 1
print_r(0 == "Every Fucking String"); // return 1

so I wanna know that why is this happening in php ?

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *