Keys →
Functions ↓
function build2DTable ( $a,$log=false ) {#-k table print format#- build an HTML table for the 2D array#-d 4/19/12 - updated for log display $spaces = ' '; if ($log) { # dump to log $colWid[0] = strlen(count($a)); # width of index col holding row numbers $c = 0; foreach ( $a[0] as $key => $value ) { $colWid[$c+1] = strlen($key); # how wide is header row $c++; } for ($r=0;$r<count($a);$r++) { # for each data row... $c = 0; foreach ( $a[$r] as $key => $value ) { $colWid[$c+1] = max($colWid[$c+1],strlen($value)); $c++; } } $tbl = "\n"; $x = ' | ' . $spaces; $tbl .= substr ( $x, 0, $colWid[0]+3 ); $colTot = $colWid[0]+3; $c = 0; foreach ( $a[0] as $key => $value ) { $x = ' | ' . $key . $spaces; $tbl .= substr ( $x, 0, $colWid[$c+1]+3 ); $c++; $colTot += $colWid[$c+1]+3; # width of entire table } $tbl .= " |\n"; $tbl .= str_repeat ( '-', $colTot+7 ) . "\n"; for ($r=0;$r<count($a);$r++) { $x = ' | ' . $r . $spaces; $tbl .= substr ( $x, 0, $colWid[0]+3 ); $c = 0; foreach ( $a[$r] as $key => $value ) { $x = ' | ' . $value . $spaces; $tbl .= substr ( $x, 0, $colWid[$c+1]+3 ); $c++; } $tbl .= " |\n"; } $tbl .= str_repeat ( '-', $colTot+7 ) . "\n"; } else { $tbl = '<br><table><tr><th>row</th>'; foreach ( $a[0] as $key => $value ) { $tbl .= '<th>' . $key . '</th>'; } $tbl .= '</tr>'; for ($i=0; $i < count($a); $i++) { $tbl .= '<tr><td>' . $i . '</td>'; foreach ( $a[$i] as $key => $value ) { $tbl .= '<td>' . $value . '</td>'; } $tbl .= '</tr>'; } $tbl .= '</table><br>'; } prt ( $tbl,1 ); }?>