<?php
$dados = array("1","2","3","4","5","6","7","8");
echo '
<div class="container">
<div class="row">'.PHP_EOL;
$i=1;
foreach($dados as $col) {
echo '<div class="col-sm-4">'.$col.'</div>';
if ($i%3==0) {
echo PHP_EOL.'</div><div class="row">'.PHP_EOL;
}
$i++;
}
echo '
</div>
</div>'.PHP_EOL;
PD9waHAKCiRkYWRvcyA9IGFycmF5KCIxIiwiMiIsIjMiLCI0IiwiNSIsIjYiLCI3IiwiOCIpOwoKZWNobyAnCjxkaXYgY2xhc3M9ImNvbnRhaW5lciI+Cgk8ZGl2IGNsYXNzPSJyb3ciPicuUEhQX0VPTDsKCgkkaT0xOwoJCglmb3JlYWNoKCRkYWRvcyBhcyAkY29sKSB7CgoJCWVjaG8gJzxkaXYgY2xhc3M9ImNvbC1zbS00Ij4nLiRjb2wuJzwvZGl2Pic7CgoJCWlmICgkaSUzPT0wKSB7CgkgCQllY2hvIFBIUF9FT0wuJzwvZGl2PjxkaXYgY2xhc3M9InJvdyI+Jy5QSFBfRU9MOwoJCX0KCgkJJGkrKzsKCX0KCgllY2hvICcKCTwvZGl2Pgo8L2Rpdj4nLlBIUF9FT0w7