Created
August 25, 2014 15:56
-
-
Save triple-j/233cd6ac1971ab2ab673 to your computer and use it in GitHub Desktop.
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 | |
function array2table( $expression, $return = false ) { | |
$expression = (array)$expression; | |
$keys = array_keys($expression[0]); | |
$html = "<table class=\"arr2tbl\">"; | |
//headers | |
$html .= "<thead>"; | |
$html .= "<tr>"; | |
foreach ( $keys as $header ) { | |
$html .= "<th>{$header}</th>"; | |
} | |
$html .= "</tr>"; | |
$html .= "</thead>"; | |
//content | |
$html .= "<tbody>"; | |
foreach ( $expression as $row ) { | |
$html .= "<tr>"; | |
foreach ( $keys as $idx ) { | |
$html .= "<td>{$row[$idx]}</td>"; | |
} | |
$html .= "</tr>"; | |
} | |
$html .= "</tbody>"; | |
$html .= "</table>"; | |
if ( $return ) { | |
return $html; | |
} else { | |
echo $html; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment