I have this array:
Array
(
[France] => Array
(
[0] => Array
(
[city] => Paris
)
)
[Canada] => Array
(
[0] => Array
(
[city] => Montreal
)
[1] => Array
(
[city] => Ottawa
)
)
)
Sometimes, like you can see a country can have one city (case for France) but sometimes the country can have more than one city (case for Canada).
I'm looking to have this final output:
<table>
<thead>
<tr>
<th>Country</th>
<th>Cities</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="1">France</td>
<td>Paris</td>
</tr>
<tr>
<td rowspan="2">Canada</td>
<td>Montreal</td>
</tr>
<tr>
<td>Toronto</td>
</tr>
</tbody>
</table>
Here's what I have actually:
foreach($countries as $country => $city) {
$count = count($country) ;
if($count == 1) {
echo '
<tr>
<td rowspan="1">'.$country.'</td>
<td>'.$city.'</td>
</tr>
'
}
else {
echo '
<tr>
<td rowspan="'.$count.'">'.$country.'</td>
<td>'.$city.'</td>
</tr>
<tr>
<td>'.$city.'</td>
</tr>
'
}
}
My problem is the loop and how to print the cities.
Thanks for any help.
$citiesnot country. Because you are deciding based on the number of cities in a country.