$a=array(
array(a,b,c),array(c,d,e),
); foreach($a as $k=>$v){ foreach($v as $value){ if(!in_array($value,$ids)) $ids[] = $value; } } foreach($a as $k=>$v){ foreach($v as $value){ foreach($ids as $key=>$id){ if($id == $value){ $res[$key]['id'] = $id; $res[$key]['num']++; } } } }dump($ids);
dump($res);