I have a quick question that I just can't seem to figure out even though it should be straightforward.
I have an associative array of the following structure:
[uk] => Array
(
[TW] => 1588
[LY] => 12936
[LW] => 13643
)
I am displaying it in an HTML table as follows.
foreach ($leads as $country) {
echo '<tr><td>' . $country . '</td><td>' . $country['TW'] . '</td><td>' . $country['LY'] . '</td><td>' . $country['LW'] . '</td></tr>';
}
but the country comes out as Array
so I'm just wondering what I am doing wrong to get the uk
part out.
Output
Array 1588 12936 13643
Use something like:
foreach ($leads as $name => $country) {
echo '<tr><td>' . $name. '</td><td>' . $country['TW'] . '</td><td>' . $country['LY'] . '</td><td>' . $country['LW'] . '</td></tr>';
}
Now, $name
in the loop is the key (in this case 'uk') and $country
is the value of the element, in this case the array (TW => 1588, LY => 12936, LW => 13643)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With