How to add up the figures of the same day? Printed as correct json

this is the result of the query

clipboard.png

this is the php query code

SELECT
FROM_UNIXTIME(add_time, "%Y-%m-%d") as add_time,
count(view_id) as viewTime
FROM `view`
GROUP BY `add_time`

this is the whole php code

header("Content-type: application/json");
    $chartData = $pdo->query(
      "SELECT
FROM_UNIXTIME(add_time, "%Y-%m-%d") as add_time,
count(view_id) as viewTime
FROM `view`
GROUP BY `add_time` "
    );

    $data = array();
    $key = 0;
    foreach ($chartData as $item){
      $data[$key] = array(
        "date" => $item["add_time"],
        "number" => $item["viewTime"]
      );

      $keyPP;
    }
    echo json_encode($data);

print results

[{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"}.............

the viewTime on the right is all data
, but what I want to implement is
date duplicates as long as a
is shown, but the numbers of the same date are all added up
. How can this be achieved?
I"m going to print out a json like this at the back end
with a sense of principle if possible

May.22,2021

$data = array();
foreach ($chartData as $item) {
  if (isset($data[$item['add_time']])) {
    $data[$item['add_time']]['number'] += $item['viewTime'];
  } else {
    $data[$item['add_time']] = array(
      'date' => $item['add_time'],
      'number' => $item['viewTime']
    );
  }
}
$data = array_values($data);
echo json_encode($data);
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3506c-2bf54.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3506c-2bf54.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?