Created
April 29, 2014 07:22
-
-
Save thealscott/11392835 to your computer and use it in GitHub Desktop.
Iterating over elements and applying marker class to achieve nth-of-class selection
This file contains 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
<?php | |
$elements = array( | |
array( | |
'id' => 1, | |
'is_test' => false | |
), | |
array( | |
'id' => 2, | |
'is_test' => true | |
), | |
array( | |
'id' => 3, | |
'is_test' => false | |
), | |
array( | |
'id' => 4, | |
'is_test' => true | |
), | |
array( | |
'id' => 5, | |
'is_test' => false | |
) | |
); | |
$test_count = 0; | |
?> | |
<?php foreach($elements as $element): ?> | |
<div class="<?php | |
if ($element['is_test']){ | |
$test_count += 1; | |
echo 'test '; | |
if ($test_count % 2 == 0) { | |
echo 'marker '; | |
} | |
} | |
?>"> | |
Test <?php echo $element['id']; ?> | |
</div> | |
<?php endforeach ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment