根据月份显示阵列数据

时间:2018-09-26 06:15:28

标签: php loops

我有如下所示的数组。每种产品的数组数据可能从1月到12月不等

Array
(
[0] => Array
    (
        [0] => Array
            (
                [SalesYear] => 2018
                [SalesMonth] => July
                [TotalSales] => 1
                [name] => Budweiser Beer 330ml (Pack of 3)
                [code] => BB330
            )

        [1] => Array
            (
                [SalesYear] => 2018
                [SalesMonth] => August
                [TotalSales] => 2
                [name] => Budweiser Beer 330ml (Pack of 3)
                [code] => BB330
            )

        [2] => Array
            (
                [SalesYear] => 2018
                [SalesMonth] => September
                [TotalSales] => 16
                [name] => Budweiser Beer 330ml (Pack of 3)
                [code] => BB330
            )

    )

[1] => Array
    (
        [0] => Array
            (
                [SalesYear] => 2018
                [SalesMonth] => August
                [TotalSales] => 11
                [name] => Chicharon 100g
                [code] => CC100
            )

        [1] => Array
            (
                [SalesYear] => 2018
                [SalesMonth] => September
                [TotalSales] => 3
                [name] => Chicharon 100g
                [code] => CC100
            )

    )

现在,我想显示产品的每个月销售情况:

https://prnt.sc/kysxur

到目前为止,这是我尝试过的

enter image description here

谢谢

2 个答案:

答案 0 :(得分:1)

x1*k

答案 1 :(得分:0)

您将需要uksort函数,但需要在那里进行一些安排:

uksort($array, function($a1, $a2) {
        $time1 = strtotime($a1);
        $time2 = strtotime($a2);

        return $time1 - $time2;
    });

print_r($ar);

,月份应为字符串