Skip to content

Instantly share code, notes, and snippets.

@Mte90
Last active May 21, 2016 22:42
Show Gist options
  • Save Mte90/5aee3fbc1df3884d42be to your computer and use it in GitHub Desktop.
Save Mte90/5aee3fbc1df3884d42be to your computer and use it in GitHub Desktop.
Table from array in PHP
<?php
function table_from_array( $cols, $tableclass = 'info' ) {
$content = "<table class=\"" . $tableclass . "\">\n";
$i = 1;
foreach ( $cols as $key => $value ) {
if ( !empty( $value ) ) {
$i++;
if ( $i % 2 === 0 ) {
$content .= "<tr>";
}
$content .= "<td class='even'>" . $key . ': ' . $value . "</td>";
if ( $i % 2 === 1 ) {
$content .= "</tr>";
}
}
}
$content .= "</table>\n";
echo $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment