Why does (0 == 'Hello') return true in PHP?
Hey, if you have got the following code and want to check if matches I've found out, that the comparison always returns if the variable is . I've came across this when an array for a special key and wondered why it's wasn't working as expected.
See this code for an example.$key
Hello
true
0
$key = 1;
if ($key != 'Hello') echo 'Hello'; //echoes hello
$key = 2;
if ($key != 'Hello') echo 'Hello'; //echoes hello
$key = 0;
if ($key != 'Hello') echo '0Hello'; //doesnt echo hello. why?
if ($key !== 'Hello') echo 'Hello'; //echoes hello
Can anyone explain this?