我正在尝试过滤两个数组以使用我的 mysql 数据库中的用户 ID 获得最终结果
我有两个数组第一个:
print_r($arr_partner_id);
Array (
[0] => Array ( [id] => 335 [id_partner] => 0 )
[1] => Array ( [id] => 469 [id_partner] => 1 )
[2] => Array ( [id] => 457 [id_partner] => 1 )
[3] => Array ( [id] => 339 [id_partner] => 0 )
[4] => Array ( [id] => 361 [id_partner] => 0 ) )
第二个:
print_r($arr_member_id);
Array (
[0] => 457
[1] => 469
[2] => 339
[3] => 361 )
现在我只想将这两个与它们的 id 进行比较,并删除未包含在“$arr_member_id”数组中的 id。这是我的“参考数组”,这意味着我只需要 id (457,469,339,361)
对于最终结果,它应该如下所示:
print_r($arr_partner_final_id);
Array (
[0] => Array ( [id] => 469 [id_partner] => 1 )
[1] => Array ( [id] => 457 [id_partner] => 1 )
[2] => Array ( [id] => 339 [id_partner] => 0 )
[3] => Array ( [id] => 361 [id_partner] => 0 ) )
我用 foreach 试过了
foreach ($arr_partner_id as $key => $usr_ids) {
if($arr_partner_id[$key]['id'] == $arr_member_id[$key]) {
// do something
}
}
但“钥匙”不同,这不应该工作......