4WebHelp
 FAQ  •  Search  •  User Groups  •  Forum Admins  •  Smilies List  •  Statistics  •  Rules   •  Login   •  Register
Toggle Navigation Menu

 PHP: Checking if number is even or uneven
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic
Author Message
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Sun Sep 29, 2002 9:54 am (15 years ago) Reply with QuoteBack to Top

Anyone know any code to check if a number is even or uneven?

I need it to make one cell out of two a different colour, in a table.

________________________________
Image

Last edited by Daniel on Tue Apr 15, 2003 7:14 pm, edited 1 time in total
OfflineView User's ProfileFind all posts by DanielSend Personal Message
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Sun Sep 29, 2002 10:28 am (15 years ago) Reply with QuoteBack to Top

Never mind; I found a solution:

Code:

$i=0;
while( blabla )
{
  $colour = ($i++ & 1) ? 'colour1' : 'colour2';
}

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
eKstreme
Ex Team Member



Joined: 12 Jan 2002
Posts: 11
Location: UK

PostPosted: Sun Sep 29, 2002 2:53 pm (15 years ago) Reply with QuoteBack to Top

Daniel wrote:
Anyone know any code to check if a number is even or uneven?

I need it to make one cell out of two a different colour, in a table.


You could use the % operator: This gives you the remainder when you divide two numbers. So any even number (by defninition) will have a remainder of zero when divided by 2. And that's how you can do it.

But you do have another solution that works in an interative context.

eKstreme
OfflineView User's ProfileFind all posts by eKstremeSend Personal MessageVisit Poster's Website
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Sun Sep 29, 2002 2:55 pm (15 years ago) Reply with QuoteBack to Top

Yeah, I found some info about that solution too, but I thought I would KISS Very Happy

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
Display posts from previous:      
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic


 Jump to:   




You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot edit your posts in this forum.
You cannot delete your posts in this forum.
You cannot vote in polls in this forum.


Page generation time: 0.053844 seconds :: 17 queries executed :: All Times are GMT
Powered by phpBB 2.0 © 2001, 2002 phpBB Group :: Based on an FI Theme