如何在PHP中比较多维数组?

时间:2018-09-21 22:18:36

标签: arrays multidimensional-array

请看一下,我有2个数组array1和array2,我想比较这些数组,并需要array2中不存在的数组。 我真的要解决这个问题,我正在开发应用程序。 所以请帮我解决这个问题 提前致谢。 这是数组1

Array
(
    [0] => Array
        (
            [image_id] => 4
            [user_id] => 2
            [user_type] => user
            [canvas_id] => 1
            [canvas_mac] => 123.234.232.121
        )

    [1] => Array
        (
            [image_id] => 3
            [user_id] => 2
            [user_type] => user
            [canvas_id] => 1
            [canvas_mac] => 123.234.232.121
        )

    [2] => Array
        (
            [image_id] => 2
            [user_id] => 2
            [user_type] => user
            [canvas_id] => 1
            [canvas_mac] => 123.234.232.121
        )

    [3] => Array
        (
            [image_id] => 1
            [user_id] => 2
            [user_type] => user
            [canvas_id] => 1
            [canvas_mac] => 123.234.232.121
        )
)

这是array2

Array
(
    [0] => Array
        (
            [image_id] => 1
            [user_id] => 2
            [user_type] => user
            [canvas_id] => 1
            [canvas_mac] => 123.234.232.121
        )
    [1] => Array
        (
            [image_id] => 4
            [user_id] => 2
            [user_type] => user
            [canvas_id] => 1
            [canvas_mac] => 123.234.232.121
        )
)

我需要这样的结果

结果数组

Array(
    [0] => Array
        (
            [image_id] => 3
            [user_id] => 2
            [user_type] => user
            [canvas_id] => 1
            [canvas_mac] => 123.234.232.121
        )

    [1] => Array
        (
            [image_id] => 2
            [user_id] => 2
            [user_type] => user
            [canvas_id] => 1
            [canvas_mac] => 123.234.232.121
        )
)

1 个答案:

答案 0 :(得分:1)

请尝试array_udiff(http://php.net/array_udiff)。符合您的要求吗?