I have an Array that has information about all workdays/jobs that is done in a month. A month can have multiple days that has been a workday. So my Array looks like this (in JSON):
{
"id": 1,
"time": "2018-12-16",
"pages_indexed": 1024
},
{
"id": 2,
"time": "2018-12-12",
"something": 1024
},
{
"id": 3,
"time": "2018-12-09",
"something": 7
},
(....)
{
"id": 12,
"time": "2018-11-12",
"something": 7
},
{
"id": 13,
"time": "2018-11-08",
"something": 7
}
I then tried this:
$expectedArray = [];
foreach ($items as $item) {
$indexKey = substr($item['time'], 0, 7);
$expectedArray[$indexKey] = $item;
}
print_r(json_encode($expectedArray));
The problem is that the outcome is that it removes the LAST, and not the first dates and adds it to as the key. This is the output:
"2018-12": {
"id": 123456,
"time": "2018-12-09",
"something": 1029
},
"2018-11": {
"id": 123456,
"time": "2018-11-08",
"something": 1032
},
These are the first days in the list of same month. I would want and expect the output to be:
"2018-12": {
"id": 123456,
"time": "2018-12-16",
"something": 1029
},
"2018-11": {
"id": 123456,
"time": "2018-11-12",
"something": 1032
},
Hope someone could show me how i can proceed. Thank you!
timeis the highest in the month?