RE: [PHP] Anyway of knowing whether a integer is odd or even
| From: | Orr, Steve | Date: | Tue, 09 Oct 2001 20:29:48 +0000 |
| Subject: | RE: [PHP] Anyway of knowing whether a integer is odd or even | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-70534@lists.php.net to get a copy of this message | ||
Why read more than one line? Here's what I do to change the background of
odd/even rows of SQL resultset data displayed in an HTML table:
(ceil($i % 2)>0) ? ($BGcolor=$oddRow) : ($BGcolor=$evenRow);
Steve Orr
-----Original Message-----
From: J Smith [mailto:dark_panda@hushmail.com]
Sent: Tuesday, October 09, 2001 2:18 PM
To: php-general@lists.php.net
Subject: Re: [PHP] Anyway of knowing whether a integer is odd or even
Is
if ($theInt & 1)
really that much harder to read than
if ($theInt % 2 > 0)
?
And why wouldn't you want to get the most performance out of your code,
regardless of the language, scripting or otherwise? Especially when it's a
one or two character switch that makes the difference?
I doubt that PHP should be classified as a scripting language any more
than Perl is. Scripting languages are usually used to glue different
applications together, like a shell script that uses awk and sed or
whatever. PHP can be used to build applications, so it's more than a
scripting language. Interpreted language is more like it.
J
David Otton wrote:
> On Tue, 09 Oct 2001 13:07:17 -0400, you wrote:
>
>>It is generally faster
>
> (but harder to read)
>
>>to use bitwise operators...
>>
>>if ($theInt & 1)
>> print "$theInt is odd";
>>else
>> print "$theInt is even";
>>
>>This is usually the case for most languages, like C or C++ or what have
>>you. It's probably the same in PHP, since the & operator doesn't need to
>>worry about returning the remainder, just the bits that are set in both
>>$theInt and 1.
>
> I'm sure I don't want to get into this, but...
>
> If speed is that important, why would you use a scripting language?
>
> djo
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net