Skip to content

Instantly share code, notes, and snippets.

@carloscastilloc2o
Forked from jasondavis/php_array_table.php
Created January 12, 2018 10:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carloscastilloc2o/1e76492cbfad05b4b6d0c8e58b9c4cae to your computer and use it in GitHub Desktop.
Save carloscastilloc2o/1e76492cbfad05b4b6d0c8e58b9c4cae to your computer and use it in GitHub Desktop.
PHP Array to HTML Table
<?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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment