需要MultiArray未设置值的帮助

时间:2012-09-19 13:07:52

标签: php arrays

我有一个名为$mark_ary的数组,其中包含:

Array
(
    [0] => 61
    [1] => 62
    [2] => 63
    [3] => 64
    [4] => 65
    [5] => 66
    [6] => 67
    [7] => 68
)

另一个名为$special_donors_array的变量包含:

Array
(
    [0] => Array
        (
            [group_id] => 4
            [user_id] => 61
            [group_leader] => 0
            [user_pending] => 0
            [username] => tester_8
            [username_clean] => tester_8
            [user_email] => tester_8@live.com
        )

    [1] => Array
        (
            [group_id] => 5
            [user_id] => 62
            [group_leader] => 0
            [user_pending] => 0
            [username] => tester_9
            [username_clean] => tester_9
            [user_email] => tester_9@live.com
        )

)

我需要从[user_id]变量的每个父键(本例中为[0]和[1])中取每个$special_donors_array值,并将这些数字用于 UNSET 来自$mark_ary数组变量。

在达到我想要的后,$mark_ary变量将如下所示:

Array
(
    [2] => 63
    [3] => 64
    [4] => 65
    [5] => 66
    [6] => 67
    [7] => 68
)

不幸的是,我甚至无法想到一个解决方案,我甚至无法尝试思考,因为我不知道如何开始这个。我仍然需要获得更多与阵列相关的知识。

想法?

2 个答案:

答案 0 :(得分:2)

foreach($special_donors_array as $special_donor){
                foreach($mark_ary as $k => $mark){
                    if($mark == $special_donor['user_id']){
                        unset($mark_ary[$k]);
                    }
                }
            }

答案 1 :(得分:0)

foreach( $special_donors_array as $k => $v ) {
 if( isset($mark_ary[$k]) && $v['user_id'] === $mark_ary[$k] )
  unset($mark_ary[$k]);
}