Last active
February 17, 2016 11:38
-
-
Save Balamir/4163749ad753108ee85f to your computer and use it in GitHub Desktop.
PHP foreach - Close and reopen the 'tr' tag after nth record
This file contains hidden or 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 | |
| $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