我有一个名为$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
)
不幸的是,我甚至无法想到一个解决方案,我甚至无法尝试思考,因为我不知道如何开始这个。我仍然需要获得更多与阵列相关的知识。
想法?
答案 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]);
}