Skip to content
Advertisement

PHP: How can I create a new array of data from another array by counting the occurrence of dates?

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:

JavaScript

needs to be transformed to:

JavaScript

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:

JavaScript

But this only returns an array of the occurrences of the columns. So how can I deal with this the right way?

Advertisement

Answer

Try this.

JavaScript

OR

JavaScript

OR, as a one liner:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement