<?php // RAY_temp_benners.php
error_reporting(E_ALL);
$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 ) );
// ACTIVATE THIS TO LOOK AT THE ARRAY
// var_dump($arr_products);
function RAY_show_array($a)
{
// CREATE THE TABLE HEADERS
echo "<tr>";
// GET KEYS FROM ONE OF THE SUB-ARRAYS
$h = $a[0];
// WRITE TABLE HEADERS FROM THE KEYS
foreach ($h as $k => $x)
{
echo "<th>" . $k . "</th>";
}
echo "</tr>" . PHP_EOL;
// CREATE THE TABLE DATA FROM THE SUB-ARRAYS
foreach ($a as $s)
{
echo "<tr>";
// GET DATA FROM EACH SUB-ARRAY
foreach ($s as $x)
{
// WRITE THE DATA ELEMENTS INTO TD STATEMENTS
echo "<td>" . $x . "</td>";
}
echo "</tr>" . PHP_EOL;
}
}
function html_show_array2($array){
echo "<table cellspacing=\"0\" border=\"2\">\n";
RAY_show_array($array, 1, 0);
echo "</table>\n";
}
html_show_array2($arr_products);
|