PHP - 每小时计算项目[关闭]

I have a PHP array like this..

Array
(
    [0] => Array
        (
            [item] => 1
            [hour] => 04
        )

    [1] => Array
        (
            [item] => 5
            [hour] => 04
        )

    [2] => Array
        (
            [item] => 1
            [hour] => 09
        )
)

I am trying to create a new array so I can track how many items are purchased in which hour and spot hourly trends.

I think I need to end up with an array that looks like this

Array
(
    [item1] => Array
        (
            [hour04] => 1
            [hour09] => 1
        )

    [item5] => Array
        (
            [hour04] => 1
        )
)

Is this the correct approach, or is there a better way to represent the final data?

If this is all info you want to store in the array it is totally enough to use this:

Array
(
     [1] => Array ( //item 1
        (
             [4] => 1  //hour 4 has one item of item 1
             [9] => 1 
        )
     [5] => Array ( //item 5
        (
             [4] => 1
        )
)

then you have stored this in $itemsPerHour you can access it $itemsPerHour[$itemId][3]; to get how many items of $itemId were sold at hour 3.