<? $tmp1 = 0; $tmp2 = "all";
if ($tmp1 == $tmp2) echo "TRUE<br>\n"; else echo "FLASE<br>\n"; ?>
This prints "TRUE" !!!!! whats going on here?
Chris Lee
Does it work with the curlies in it like below?
if ($tmp1 == $tmp2) { echo "TRUE\n"; } else { echo "FLASE\n"; } ?>
Still says true , wierd eh. but it aint true, its false,
0 does not = 'all'
Ive tried it with ' vs " too
Apparently you need to say:
if ((string)$tmp1 == $tmp2)
though I've never seen PHP not convert appropriately between string and number before.
It is converting appropriately, it is just converting the "all" to an integer; 0
Duhhh! (Sound of hand hitting forehead.) Of course; all the it-just-works stuff I've been dealing with has been comparing things like
if ($value > 1)
where $value contains a digit-string as returned from a numeric database column. Thanks for clarifying my confusion!
This has to be the first time Ive had a problem with php type casting in the wrong spot before. I'll fix my code to be fool proof 🙂 thanks all.
Well, just out of curiousity, what should the result be of comparing a number and "all"?