I am using a multi-dimensional associative array to keep track of monthly totals, then I want to loop through it using foreach and output the contents.
The totals for each inner array are kept in element 12, and only want each array to output if the total is > 0, except "Total", which I want to output even if it is 0.
foreach($yearspend as $key => $format)
{
// only show formats with any spend
if($key == "Total" || $format[12] > 0)
{
echo "<tr><td>$key</td>";
foreach($format as $value)
{
echo "<td>".number_format($value,2)."</td>";
}
echo "</tr>";
}
}
For some reason this outputs for inner array 0, even though [0][12] is 0.
Here is the output from print_r:
Array
(
[0] => Array
(
[12] => 0
)
[Group] => Array
(
[12] => 0
)
[Total] => Array
(
[12] => 0
)
)
Please can anyone help?