Skip to content

Instantly share code, notes, and snippets.

@Balamir
Last active February 17, 2016 11:38
Show Gist options
  • Select an option

  • Save Balamir/4163749ad753108ee85f to your computer and use it in GitHub Desktop.

Select an option

Save Balamir/4163749ad753108ee85f to your computer and use it in GitHub Desktop.
PHP foreach - Close and reopen the 'tr' tag after nth record
<?php
$i = 0;
echo '<tr>';
foreach ($variable as $key => $value) {
$i++;
'<td>' . $key . '</td>' .
'<td>' . $value . '</td>';
// Close and reopen the 'tr' tag after fourth record
if ( $i % 4 == 0 ) {
echo '</tr>' .
'<tr>';
}
}
echo '</tr>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment