Warning: Invalid argument supplied for foreach() in /home/jihswbiz/public_html/t6.gwilt.org/refDox.php on line 212
Docs-build2DTable

 

ReLoad

Keys


Functions

arraybrowsercolorcookiedatetimeDBdebugdeviceDSTequiverrorflagsfontformatgeo
holidayhtmlisjsonmathparsePHPprintsearchsortstringtabletexttracetype
VOTDweatherxml

Function  build2DTable   Lines 328-407 (79 lines)Updated: 2012-04-19 file  utils.php   Last mod: Fri 2021-05-14 21:45:07

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 $x0$colWid[0]+);
                
$colTot $colWid[0]+3;
                
$c 0;
                foreach ( 
$a[0] as $key => $value )
                        {
                        
$x ' | ' $key $spaces;
                        
$tbl .= substr $x0$colWid[$c+1]+);
                        
$c++;
                        
$colTot += $colWid[$c+1]+3;     # width of entire table
                        
}
                
$tbl .= " |\n";
                
$tbl .= str_repeat '-'$colTot+) . "\n";

                for (
$r=0;$r<count($a);$r++)
                        {
                        
$x ' | ' $r $spaces;
                        
$tbl .= substr $x0$colWid[0]+);
                        
$c 0;
                        foreach ( 
$a[$r] as $key => $value )
                                {
                                
$x ' | ' $value $spaces;
                                
$tbl .= substr $x0$colWid[$c+1]+);
                                
$c++;
                                }
                        
$tbl .= " |\n";
                        }
                
$tbl .= str_repeat '-'$colTot+) . "\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,);
        }

?>