Re: PHP boolean's
- From: Michael Fesser <netizen@xxxxxx>
- Date: Sat, 31 May 2008 14:31:51 +0200
..oO(Michael Sharman)
I suppose I can also do;
if(!($count % 2))
Yes. But even if this is documented behaviour, it's usually recommended
to explicitly write what you want to test for. In this case you're not
testing a boolean value ('!' is a logical operator), but an arithmetic
expression. So you should better write it as
if ($count % 2 == 0) {
...
}
This is cleaner and more readable code. Another example: The typical
shorthand way for testing if an array is empty or not is
if (!$someArray) {
...
}
But the better way is
if (empty($someArray)) {
...
}
Micha
.
- Follow-Ups:
- Re: PHP boolean's
- From: Rik Wasmus
- Re: PHP boolean's
- References:
- PHP boolean's
- From: Michael Sharman
- Re: PHP boolean's
- From: petersprc
- Re: PHP boolean's
- From: Michael Sharman
- PHP boolean's
- Prev by Date: Re: include 'filename.php' vs. exit 'whatever'
- Next by Date: Re: PHP boolean's
- Previous by thread: Re: PHP boolean's
- Next by thread: Re: PHP boolean's
- Index(es):