如何组合两个列表foreach?
第一个foreach:
foreach($dataaa['friends']['data'] as $friend) { echo $friend['id'], '<br />'; }
结果:
100000247061
100000519889
100000785939
100000830825
100000941638
100001089460
100001099128
100001109591
100001289834
100001464846
100001704188
100001751965
100001772722
第二个foreach:
foreach($app_using_friends as $friend) { echo $friend['uid'], '<br />'; }
结果:
100000247061
100000519889
100000785939
如何组合列表并排除碰撞的ID?
结果:
100000830825
100000941638
100001089460
100001099128
100001109591
100001289834
100001464846
100001704188
100001751965
100001772722
答案 0 :(得分:3)
您需要使用array_diff
:
$arr = array_diff(
array_map(
function ($e) {
return $e['id'];
},
$dataaa['friends']['data']
), array_map(
function ($e) {
return $e['uid'];
},
$app_using_friends
)
);
// And then your output:
foreach($arr as $friend) { echo $friend, '<br />'; }
答案 1 :(得分:1)
您可以使用 array_unique :
$list = array_unique(array_merge(
array_map(function($e) { return $e['id']; }, $dataaa['friends']['data']),
array_map(function($e) { return $e['uid']; }, $app_using_friends)
));