-2
I am trying to bring to a simpler way the following information coming from an API:
{
"results": [
{
"date": "2020-01-05T00:00:00Z",
"total": 100,
"visits_detail": [
]
},
{
"date": "2020-01-06T00:00:00Z",
"total": 200,
"visits_detail": [
]
},
{
"date": "2020-01-07T00:00:00Z",
"total": 300,
"visits_detail": [
]
}
]
}
What I want to do is turn this part of the code into something like this, turning the date from ISO8601 Standard to Datetime, so I won’t have trouble displaying the data with Apexchart.
{
"results": [
{
"date": "05-01-2020",
"total": 100,
"visits_detail": [
]
},
{
"date": "06-01-2020"",
"total": 200,
"visits_detail": [
]
},
{
"date": "07-01-2020"",
"total": 300,
"visits_detail": [
]
}
]
}
Turns out I stalled and I can’t get all the information accessed inside the foreach. That’s my code:
foreach ($myArray2['results'] as $key => $value)
{
$data1 = date('d-m-Y', strtotime($myArray2['results'][$key]['date']));
$data2 = $myArray2['results'][$key]['total'];
}
$arrayfinal = array('results'=> (array('date'=>$data1,'total'=>$data2)));
echo json_encode($arrayfinal);
And the answer I get is just this, I can’t display all the items, and it’s not array format.
{
"results": {
"date": "07-01-2020",
"total": 300
}
}
How I can insert in the same array the Total of visits on each date?
– João Fernando Zanato