首頁 > 後端開發 > php教程 > 怎么取数组的交集,求大神指导

怎么取数组的交集,求大神指导

WBOY
發布: 2016-06-20 12:36:43
原創
1100 人瀏覽過

这是两个二维数组$arr,$arr1,怎么取出相同的交集$arr = array(		array("id" => "3","name" => "张三"),		array("id" => "6","name" => "李四"),		array("id" => "8","name" =>  "王五"),		array("id" => "18","name" => "赵六"),	 	array("id" => "20","name" => "七七")	 );$arr1 = array(		array("id" => "6","name" => "张三",),                array("id" => "18","name" => "赵六"),);想要的结果是array(		array("id" => "6","name" => "张三",),                array("id" => "18","name" => "赵六"));
登入後複製


回复讨论(解决方案)

$arr = array(        array("id" => "3","name" => "张三"),        array("id" => "6","name" => "李四"),        array("id" => "8","name" =>  "王五"),        array("id" => "18","name" => "赵六"),        array("id" => "20","name" => "七七")     );$arr1 = array(        array("id" => "6","name" => "张三",),        array("id" => "18","name" => "赵六"),);foreach($arr as $a)  foreach($arr1 as $k=>$b)    if($a == $b) {      $r[] = $b;      unset($arr1[$k]);    }print_r($r);
登入後複製
Array(    [0] => Array        (            [id] => 18            [name] => 赵六        ))
登入後複製

可是我想要的结果是这个:

$arr1 = array(        array("id" => "6","name" => "张三",),        array("id" => "18","name" => "赵六"),);
登入後複製

是我看错了,sorry

來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板