You are here: Re: 0 vs false « PHP Programming Language « IT news, forums, messages
Re: 0 vs false

Posted by Jerry Stuckle on 04/24/06 07:04

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
==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация