$arr_products = array( array( 'Code' => 'TIR', 'Description' => 'Tires', 'Price' => 100 ), array( 'Code' => 'OIL', 'Description' => 'Oil', 'Price' => 10 ), array( 'Code' => 'SPK', 'Description' => 'Spark Plugs', 'Price' =>4 ) );
function show_array2($array, $level, $sub){
if (is_array($array) == 1){ // check if input is an array
foreach($array as $key_val => $value) {
if (is_array($value) == 1){ // array is multidimensional
echo "<tr>";
show_array2($value, $level+1, 1);
}
else{ // (sub)array is not multidim
if ($sub != 1){ // first entry for subarray
echo "<tr nosub>";
}
$sub = 0;
echo "<td main ".$sub." width=\"120\">" . $key_val . "</td><td width=\"120\">" . $value . "</td>";
echo "</tr>\n";
}
} //foreach $array
}
else{ // argument $array is not an array
return;
}
}
function html_show_array2($array){
echo "<table cellspacing=\"0\" border=\"2\">\n";
show_array2($array, 1, 0);
echo "</table>\n";
}
html_show_array2($arr_products);
|