Skip to content

Instantly share code, notes, and snippets.

@thealscott
Created April 29, 2014 07:22
Show Gist options
  • Save thealscott/11392835 to your computer and use it in GitHub Desktop.
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
<?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