I want to re-arrange/ group this array by date, and merge values with the same date.
Array
(
[0] => stdClass Object
(
[pc] => 100
[date] => 2017-10-03
)
[1] => stdClass Object
(
[pi] => 1
[date] => 2017-10-16
)
[2] => stdClass Object
(
[so] => 10
[date] => 2017-10-12
)
[3] => stdClass Object
(
[so] => 2
[date] => 2017-10-16
)
)
Output will be:
Array
(
[0] => stdClass Object
(
[date] => 2017-10-03
[pc] => 100
)
[1] => stdClass Object
(
[date] => 2017-10-12
[so] => 10
)
[2] => stdClass Object
(
[date] => 2017-10-16
[pi] => 1
[so] => 2
)
)
I had tried:
$new = array();
foreach ($query as $opt) {
$date = date('Y-m-d',strtotime($opt->date));
$new[$date] = $opt;
}