Re: PHP boolean's
- From: petersprc <petersprc@xxxxxxxxx>
- Date: Fri, 30 May 2008 18:57:07 -0700 (PDT)
The not operator (!) has higher precedence and is evaluated prior to
the mod operator.
You can use: if ($count % 2 == 0)
Precedence list:
http://us.php.net/manual/en/language.operators.php#language.operators.precedence
As for your other question about boolean comparisons, here are the
rules on boolean conversion:
http://us2.php.net/manual/en/language.types.boolean.php#language.types.boolean.casting
Regards,
John Peters
On May 30, 9:38 pm, Michael Sharman <sha...@xxxxxxxxx> wrote:
Can anyone confirm if in PHP 0 = FALSE and anything else if TRUE?
Or is it more 0 = FALSE and 1 = TRUE?
One of the reasons I ask is that if I do;
//$count is an incrementing value starting from 0 in a loop
if($count % 2)
{
//do something
}
This works fine, but if I do:
if(!$count % 2)
{
//do something
}
It doesn't work. Should it not just be a boolean comparison? Why do I
need to do this to get my FALSE?
if($count % 2 === 0)
{
}
.
- Follow-Ups:
- Re: PHP boolean's
- From: Michael Sharman
- Re: PHP boolean's
- References:
- PHP boolean's
- From: Michael Sharman
- PHP boolean's
- Prev by Date: Re: Sudden increase in php-jobs
- Next by Date: able to upload 28 meg file, yet php.ini limits posts to 10 megs. What is up with that?
- Previous by thread: PHP boolean's
- Next by thread: Re: PHP boolean's
- Index(es):