2016-07-21 18 views
0

で別の配列になっていない場合は、マルチdiementionalた配列の要素を取得する方法:1つの配列の要素は、次のように私はPHPでの二つの配列を持つ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)); 

アレイのuser_idを取得するにはapproved_usersは、approval_usersでご利用いただけません。この例では

、それが配列に事前に

[1] => Array ([user_id] => 3 [username] => 
demo [remark] => as approved [status] => Approved). 

感謝を返す必要があります。以下

答えて

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; 
} 

Live demo

+0

はい、それは解決策を働いています。ありがとう – user3391137

関連する問題