I need your help. I want to prepare some data from a multidimensional array of objects to equal with the ChartJS data structure:
https://www.chartjs.org/docs/master/general/data-structures/
So for example this array here:
$source = [
[
'id' => '123',
'date_created' => '2020-10-19 22:50:46'
],
[
'id' => '456',
'date_created' => '2020-10-19 13:50:19'
],
[
'id' => '276',
'date_created' => '2020-09-19 11:50:46'
],
[
'id' => '846',
'date_created' => '2020-09-19 21:50:46'
],
[
'id' => '543',
'date_created' => '2020-10-18 22:50:46'
]
];
needs to be transformed to:
$dest = [
'2020-10-19' => '2',
'2020-09-19' => '2',
'2020-10-18' => '1'
];
So logically the functions needs to count the occurrence of timestamps in an array only by the date (not the time). After that a new array must be created with the date as key and the occurrences of it as a value.
I've tried using this:
error_log( print_r( array_count_values( array_flip( array_column( $source, 'date_exported' ) ) ), true ) );
But this only returns an array of the occurrences of the columns. So how can I deal with this the right way?