Jump to content

How do I use PHP arrays to populate an HTML table


dude32

Recommended Posts

There are so many ways to do this. Heres one very general one.

 

<html>
<table>
<?php
$arr = array("apple", "orange", "banana");
foreach ($arr as $key => $value) 
{
   echo "<tr>
           <td>Key:".$key."</td>
           <td>Value:".$value."</td>
         </tr>";
}
?>
</table>
</html>

 

Will produce something along the lines of...

Key: 0  Value: apple
Key: 1 	Value: orange
Key: 2 	Value: banana

 

http://www.php.net/foreach

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.