Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Need help understanding this.
Old 07-13-2010, 03:05 PM Need help understanding this.
grafitti's Avatar
Novice Talker

Posts: 9
Trades: 0
Can someone explain to me to the logic behind the %2. Although I do know the variable $i is changing every time it loops. I'd like to know what the %2 means.
PHP Code:
$i=0;
while(
$i 10){
    
    if(
$i%2){
        
$color 'class="blue"';
    }
    else{
    
$color 'class="red"';    
    }
    echo 
'<h2 '.$color.'>Text</h2>';
    
    
$i++;

grafitti is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-13-2010, 03:13 PM Re: Need help understanding this.
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
% is the modulus operator. It gives the remainder of an integer division of the operands.

In this case, $i % 2 will be 1 if $i is even, and 0 if it is odd.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 07-13-2010, 03:15 PM Re: Need help understanding this.
grafitti's Avatar
Novice Talker

Posts: 9
Trades: 0
Thanks appreciate it.
grafitti is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Need help understanding this.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31757 seconds with 12 queries