这不能为TRUE [重复]

$vartest = 0;

if ($vartest == "This can't be TRUE")  { echo "But it is TRUE"; }

>> But it is TRUE

By mistake I made a wrong declaration somewhere in my program, and discovered this strange behaviour.

I used $vartest = “” most of the time, but somewhere $vartest = 0 slipped into the program.

Because I spent hours to find the error I’m posting this just for awareness.

Just one question. The variable $vartest is empty, but why does PHP find this TRUE ?

</div>

You had to compare on equality and type with "===" and not only with "==" for equality with typeconversion. Try this:

$vartest = 0;

if ($vartest === "This can't be TRUE")  { echo "But it is TRUE"; }