php - Work out percentage to auto-populate HTML Table -
i have following code:
function getpercent($arg){ $count = count($arg); return /* confused here */; } $test_array = array( "id" => 1, "user" => "test", "perm" => 1, "test" => "string" );
i'm going populate html table column count($test_array)
, need have percentages put inside table attrib:
<td align=left style="width:xx%">
but, how go working out percentage?
use floor() round down don't end total percentage of on 100%, , pass array function average width.
<?php function getpercent($arg){ $count = count($arg); return floor( 100 / $count ); } $test_array = array( "id" => 1, "user" => "test", "perm" => 1, "test" => "string" ); $average_widths = getpercent($test_array); // in case return 25 // ...table tags here etc etc etc // output results foreach( $test_array $key => $value ) { echo '<td align=left style="width:' . $average_widths . '%">'; echo $key . ' -> ' . $value; echo '</td>'; } ?>
Comments
Post a Comment