Last active
May 21, 2016 22:42
-
-
Save Mte90/5aee3fbc1df3884d42be to your computer and use it in GitHub Desktop.
Table from array in PHP
This file contains 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 | |
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