Latest Articles
 by awuehr on 11-10-2008 in Tips & Tricks by Village Idiot on 11-04-2008 in Classes & Objects by codefreek on 10-23-2008 in Basic by wiifanatic on 09-12-2008 in Security & Permissions by drewbee on 07-03-2008 in Tips & Tricks
 IRC Channel
 Join the friendly bunch on IRC... (#TalkPHP on Freenode) ...Also available via a web interface. See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
 Associates
 Associates
 TalkPHP » Don't know what this does
 08-11-2010, 03:42 PM #1 (permalink) The Visitor   Join Date: Jun 2010 Posts: 4 Thanks: 1 Don't know what this does I was following a tutorial I found about some database class and it uses the following code: Code: ```if(\$i%2 != 0){ /**/ }``` My question is: what does the %(int) do? Divide the \$i var? Thanks in advance.
 08-11-2010, 04:43 PM #2 (permalink) The Addict     Join Date: Aug 2008 Posts: 336 Thanks: 8 it checks if the number \$i (I am guessing \$i value's is a number) is odd or even/ The modular or mod (%) returns the reminder of the division, such as if the statement is 4%3 it would be the reminder of the 4/3 division which in this case example is 1. On the example code you gave if anything divided by 2 doesn't return 0 then the nominator is odd. I think it is a mathematical way to find odd or even numbers.
 08-12-2010, 02:54 PM #3 (permalink) The Prestige         Join Date: Oct 2007 Location: Manchester, UK Posts: 854 Thanks: 32 Yep, the modulo operator returns the remainder of division of one number by another. The above code could be condensed slightly. Because PHP treats return values of anything other than False/Null or '0' etc as true, we can just do this: PHP Code: ``` if(\$i % 2){}  ``` __________________ mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0; Empty set (0.00 sec)
 08-14-2010, 03:58 PM #4 (permalink) The Visitor   Join Date: Jun 2010 Posts: 4 Thanks: 1 Thanks alot, cheers

 Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)