Re: 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

Re: 0 vs false

From: Jerry Stuckle <jstucklex@attglobal.net>
Date: Mon Apr 24 2006 - 06:04:11 CEST

esingley@gmail.com wrote:
> 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.
>

if (strpos("foo bar", "foo") !== false) {
   echo "foo found";
}

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Received on Mon May 1 03:02:40 2006