Created
July 13, 2013 18:42
-
-
Save dvidsilva/5991759 to your computer and use it in GitHub Desktop.
creates a table using an array
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
public function table($array,$headers,$title){ | |
$table = ''; | |
$table .= "<table id=table class=table >\n"; | |
if($title != ''){ | |
$table .= "<caption >$title</caption>\n"; | |
} | |
$table .=" <thead><tr>\n"; | |
$r = 1; | |
if(!is_array($headers)){ | |
$headers = array_keys($array[0]); | |
} | |
foreach ($headers as $head){ | |
$head = str_replace('_',' ',$head); | |
$table.=" <th>".$head."</th>\n"; | |
} | |
$table .= " </tr></thead><tbody>\n"; | |
foreach ($array as $l){ | |
if($r % 2){ $odd= ' odd ';}else{$odd = '';} | |
$table.=" <tr class='$odd'>\n"; | |
foreach($l as $c){ | |
$table .= "<td>$c</td>"; | |
} | |
$table .= " </tr>\n"; | |
$r++; | |
} | |
$table .= "</tbody></table>\n"; | |
return($table); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment