My controller is returning a time-series array for a graph, it also needs the total views count. The array it returns is in this format, need to calculate the sum of views corresponding ot the dates.
framework: Laravel
[
{
"2021-04-30": 0,
"2021-05-01": 0,
"2021-05-02": 0,
"2021-05-03": 0,
"2021-05-04": 0,
"2021-05-05": 0,
"2021-05-06": 1
}
]
$result = $as->getVisits();
$array = json_decode($result,1);
$total = 0;
foreach($array[0] as $date => $visits)
$total += 1;
echo $total;
return [$result, $total];