Created
June 30, 2016 07:15
-
-
Save jasondavis/6ea170677014aa65aa2ba25269ae16dc to your computer and use it in GitHub Desktop.
PHP Array to HTML Table
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 html_table($data = array()) | |
{ | |
$rows = array(); | |
foreach ($data as $row) { | |
$cells = array(); | |
foreach ($row as $cell) { | |
$cells[] = "<td>{$cell}</td>"; | |
} | |
$rows[] = "<tr>" . implode('', $cells) . "</tr>"; | |
} | |
return "<table class='hci-table'>" . implode('', $rows) . "</table>"; | |
} | |
$data = array( | |
array('1' => '1', '2' => '2'), | |
array('1' => '111', '2' => '222'), | |
array('1' => '111111', '2' => '222222'), | |
); | |
echo html_table($data); |
This function will not work, if you have multi dimenstional array.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great, what about do you have any solution for it?