0 vs false
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

0 vs false

From: <esingley@gmail.com>
Date: Mon Apr 24 2006 - 04:42:02 CEST

So, this was driving me insane today, and I'm sure there's an easy
answer that I'm just missing.

Say I have an expression where 0 is acceptable as a TRUE response. But
how, in PHP, do I say that 0 = true since it treats 0 = FALSE = "".
For example, if I look for "foo" in a string using strpos:

if (strpos("foo bar", "foo")) {
   echo "foo found at the beginning of the phrase.";
}

This should evaluate to TRUE, but it doesn't since it finds "food" at
position 0, which then evaluates to FALSE.

I tried casting, isset, is_null, and a few other siller options. I
eventually worked around it by using substr_count, but mostly I'm just
curious about the general answer to the question.

Thanks.
Received on Mon May 1 03:02:38 2006