我在PHP中有两个数组如下:
approval_users:
Array ( [0] => Array ( [user_id] => 2 [username] => aamir [remark] => as
approved [levels] => 1 [status] => Approved ) [1] => Array ( [user_id] =>
[username] => easy [remark] => [levels] => 2 [status] => - ));
approved_users
Array ( [0] => Array ( [user_id] => 2 [username] => aamir [remark] => as
approved [status] => Approved ) [1] => Array ( [user_id] => 3 [username] =>
demo [remark] => as approved [status] => Approved ));
如何在 approved_users 中获取 approved_users 中的数组的user_id?
在这个例子中,它应该返回数组
[1] => Array ( [user_id] => 3 [username] =>
demo [remark] => as approved [status] => Approved ).
提前致谢。
答案 0 :(得分:1)
$results
将包含您想要的内容:
// list of all IDs in $approval_users
$approval_users_ids = array_column($approval_users, 'user_id');
$results = [];
foreach($approved_users as $user){
//if current approved_user is not found in the list, add it to results
if(!in_array($user['user_id'],$approval_users_ids)) $results[]=$user;
}