Last active
August 29, 2015 14:12
-
-
Save malinky/7fb1bbf9febe8743c98f to your computer and use it in GitHub Desktop.
Loop Counters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Bitwise Check | |
* If $count is an odd number returns true (1st expression). | |
*/ | |
echo $count & 1 ? '' : '' ; | |
/** | |
* Bitwise Check Usage | |
* Add a class 'end' on every even loop (when expression returns false). | |
*/ | |
$count = 0; | |
echo ++$count & 1 ? '' : ' end' ; | |
/** | |
* Modulus | |
* Every third $count returns true (1st expression). | |
* Can use any modulus not just 3. | |
*/ | |
echo $count % 3 == 0 ? '' : '' ; | |
/** | |
* Modulus Usage | |
* Add a class 'end' on every 3rd loop. | |
*/ | |
$count = 0; | |
echo ++$count % 3 == 0 ? ' end' : '' ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment