Populate elements into table

I am trying to take my arrays and display some kind of table like the one below.

+--------------+-------------+--------------+------------------+
|   product    | total_sales | unit_price   |      units_sold  |
+--------------+-------------+--------------+------------------+
| cucumber     |      100.25 |        90.00 |                2 |
+--------------+-------------+----------------+----------------+

How would I do that in php so that the table shows up on the front end of the page?

I was able to get what I needed with this code

$table = array( array("Id", "Sales" , "Price"),
                array("1", "100.25" , "90.00"),
                array("2", "125.00" , "65.00"),
				
             );  
        

foreach ($table as $rows => $row)
{
	echo "<table border='1' cellspacing='0' cellpadding='0' style='border-style: dotted'><tr>";
	foreach ($row as $col => $cell)
	{
		echo "<td width='75'>" . $cell . "</td>";
	}	
  echo "</tr></table>";
}

Does the resulting view-source table mark-up look OK for that?

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.