note 57618 deleted from ref.array by aidan

From: Date: Sun, 09 Oct 2005 08:29:46 +0000
Subject: note 57618 deleted from ref.array by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-96718@lists.php.net to get a copy of this message
Note Submitter: Nick Bullock - SafireX Reason: useless ---- This is a function to easily output an array as an HTML table. Useful for debuging, displaying MySQL output and an alternative to print_r(). <? function array2table($arr,$width) { $count = count($arr); if($count > 0){ reset($arr); $num = count(current($arr)); echo "<table align=\"center\" border=\"1\"cellpadding=\"5\" cellspacing=\"0\" width=\"$width\">\n"; echo "<tr>\n"; foreach(current($arr) as $key => $value){ echo "<th>"; echo $key."&nbsp;"; echo "</th>\n"; } echo "</tr>\n"; while ($curr_row = current($arr)) { echo "<tr>\n"; $col = 1; while ($curr_field = current($curr_row)) { echo "<td>"; echo $curr_field."&nbsp;"; echo "</td>\n"; next($curr_row); $col++; } while($col <= $num){ echo "<td>&nbsp;</td>\n"; $col++; } echo "</tr>\n"; next($arr); } echo "</table>\n"; } } ?> <? $test = array( 0 => array( "a" => 6, "b" => 25, "c" => 14 ), 1 => array( "a" => 42, "b" => 75, "c" => 172 ), 2 => array( "a" => 12, "b" => 85, "c" => 17 ), 3 => array( "a" => 85, "b" => 74, "c" => 41 ), 4 => array( "a" => 63, "b" => 82, "c" => 19 ), 5 => array( "a" => 91, "b" => 788, "c" => 787 ) ); array2table($test,400); // Will output a table of 400px width ?>

« previous php.notes (#96718) next »