本文介绍了阵列的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要得到这两个数组之间的区别,我试过和array_diff($数组1,$数组2)没有成功,任何想法?

I need to get the difference between these two arrays, I've tried array_diff($array1,$array2) without success, any idea?

数组1

Array
(
    [0] => Array
        (
            [status] => 61192106047320064
        )

    [1] => Array
        (
            [status] => 61185038284357632
        )

    [2] => Array
        (
            [status] => 61182890951720960
        )

)

数组2

Array
(
    [0] => Array
        (
            [status] => 61185038284357632
        )

    [1] => Array
        (
            [status] => 61182890951720960
        )

)

先谢谢了。

推荐答案

也许我是误会,但你就不能这样做对您的具体问题?

Maybe I'm misunderstanding, but can't you just do something like this for your specific problem?

$newStatuses = array();

foreach($array1 as $element1) {
    foreach($array2 as $element2) {
        if($element1['status'] == $element2['status']) {
            continue 2;
        }
    }

    $newStatuses[] = $element1;
}

$ newStatuses的每个元素都将与在array1一个'状态'要素,这不是在数组2数组。

Each element of $newStatuses will be an array with a 'status' element from array1 that was not in array2.

所以,$ newStatuses会是这样:

So, $newStatuses would be this:

Array
(
    [0] => Array
        (
            [status] => 61192106047320064
        )

)

这篇关于阵列的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 01:52