|
Posted by esingley on 04/24/06 05:42
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.
Navigation:
[Reply to this message]
|