3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $count = 0; $count_total = 10; $columns = 3; $all_posts = array(1,2,3,4,5,6,7,8,9,10); foreach ($all_posts as $k => $v) { $count++; $is_first_column = false; if ($count == 1 || ($count-1) % $columns == 0) { $is_first_column = true; } echo '<article id="post-' . $k . '" class="post-col ' . ($is_first_column ? 'column_1' : '') . '">'; }
Output for 4.3.0 - 7.1.0
<article id="post-0" class="post-col column_1"><article id="post-1" class="post-col "><article id="post-2" class="post-col "><article id="post-3" class="post-col column_1"><article id="post-4" class="post-col "><article id="post-5" class="post-col "><article id="post-6" class="post-col column_1"><article id="post-7" class="post-col "><article id="post-8" class="post-col "><article id="post-9" class="post-col column_1">