Skip to content

Instantly share code, notes, and snippets.

@malinky
Last active August 29, 2015 14:12
Show Gist options
  • Save malinky/7fb1bbf9febe8743c98f to your computer and use it in GitHub Desktop.
Save malinky/7fb1bbf9febe8743c98f to your computer and use it in GitHub Desktop.
Loop Counters
/**
* 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