0
1.Why the output of the following programme is 1 ?
<?php if(""==0) echo 1; else echo 0; echo "<br/>"; ?>
2 Answers
+ 2
any string when type casted to integer will be 0.. so 0==0 is true therefore it produces output as 1.
u can try as "hello"==0 it will also be true..
but remember
"hello"==null will be false since null is not an integer and neither the String after type casting will be equal to null..
+ 1
it is because the operator == automatically converts the string "" in an int, but the type conversion in this case returns 0, so 0 == 0 is True
for example ("1"==0) is False because in this case the type conversion from "1" to int can be done and it becomes 1.
in your case use === that will return False because it doesn't modify the type of the variables