I have an array that includes some other arrays. All values which are inside that array, should be placed in a HTML table. I get all the values but my HTML table looks horrible!
I have a code that looks like this:
<?php
$data = array(
'name' => array('Tom', 'Robert', 'Julia'),
'age' => array(32, 45, 21),
'city' => array('New York', 'Toronto', 'Los Angeles')
);
?>
<table>
<tr>
<td>Name</td>
<td>Age</td>
<td>City</td>
</tr>
<tr>
<?php
foreach($data as $values) {
foreach($values as $value) {
echo '<td>' . $value . '</td>';
}
}
?>
</tr>
</table>
The output of this code will be:
<table>
<tr>
<td>Name</td>
<td>Age</td>
<td>City</td>
</tr>
<tr>
<td>Tom</td>
<td>Robert</td>
<td>Julia</td>
<td>32</td>
<td>45</td>
<td>21</td>
<td>New York</td>
<td>Toronto</td>
<td>Los Angeles</td>
</tr>
</table>
This is exactly the output that I need:
<table>
<tr>
<td>Name</td>
<td>Age</td>
<td>City</td>
</tr>
<tr>
<td>Tom</td>
<td>32</td>
<td>New York</td>
</tr>
<tr>
<td>Robert</td>
<td>45</td>
<td>Toronto</td>
</tr>
<tr>
<td>Julia</td>
<td>21</td>
<td>Los Angeles</td>
</tr>
</table>
How can I do this?
echo ... foreach(...) {...} echo...