1

我有一个名为的数组$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,并使用这些数字从数组变量中取消设置它们。$mark_ary

在实现我想要的之后,$mark_ary变量将如下所示:

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

不幸的是,我什至想不出解决方案,我什至无法尝试,因为我不知道如何开始。我仍然需要获得更多与数组相关的知识。

想法?

4

2 回答 2

2
foreach($special_donors_array as $special_donor){
                foreach($mark_ary as $k => $mark){
                    if($mark == $special_donor['user_id']){
                        unset($mark_ary[$k]);
                    }
                }
            }
于 2012-09-19T13:13:04.433 回答
0
foreach( $special_donors_array as $k => $v ) {
 if( isset($mark_ary[$k]) && $v['user_id'] === $mark_ary[$k] )
  unset($mark_ary[$k]);
}
于 2012-09-19T13:11:08.587 回答