找出多维数组的差异

时间:2014-04-08 07:07:23

标签: php mysql

我想找到下面数组的不同。

第一个阵列:

Array
(
[0] => Array
    (
        [MONTH] => 1
        [year] => 2014
        [Total_days] => 2
    )

[1] => Array
    (
        [MONTH] => 2
        [year] => 2014
        [Total_days] => 2
    )

[2] => Array
    (
        [MONTH] => 3
        [year] => 2014
        [Total_days] => 2
    )

[3] => Array
    (
        [MONTH] => 4
        [year] => 2014
        [Total_days] => 2
    )

[4] => Array
    (
        [MONTH] => 6
        [year] => 2014
        [Total_days] => 1
    )

[5] => Array
    (
        [MONTH] => 1
        [year] => 2015
        [Total_days] => 1
    ))

第二阵列:

Array
(
[0] => Array
    (
        [MONTH] => 1
        [year] => 2014
        [total] => 4
    )

[1] => Array
    (
        [MONTH] => 2
        [year] => 2014
        [total] => 6
    )

[2] => Array
    (
        [MONTH] => 3
        [year] => 2014
        [total] => 5
    )

[3] => Array
    (
        [MONTH] => 4
        [year] => 2014
        [total] => 6
    )

[4] => Array
    (
        [MONTH] => 5
        [year] => 2014
        [total] => 2
    )

[5] => Array
    (
        [MONTH] => 6
        [year] => 2014
        [total] => 2
    )

[6] => Array
    (
        [MONTH] => 7
        [year] => 2014
        [total] => 2
    )

[7] => Array
    (
        [MONTH] => 8
        [year] => 2014
        [total] => 1
    )

[8] => Array
    (
        [MONTH] => 9
        [year] => 2014
        [total] => 1
    )

[9] => Array
    (
        [MONTH] => 10
        [year] => 2014
        [total] => 2
    ))

现在如何在同一年和同一个月找到array2到array1之间的总差异?

例如,在array2中有array [6] =>排列         (             [MONTH] => 7             [year] => 2014             [total] => 2         )

在array1中,索引数组[4]中的年份和月份相同。这里如何找到总差异为2-1 = 1?

2 个答案:

答案 0 :(得分:0)

尝试使用array_diff方法查找array中的差异。

答案 1 :(得分:0)

首先附加年,月和日....然后使用date_diff()

找到差异