1 <?php 2 $arr1 = array(1, 3, 5, 8, 9); 3 $arr2 = array(1, 3, 4, 7, 9); 4 $intersaction= array(); 5 foreach($arr1 as $val) { 6 if(in_array($val, $arr2)) $intersaction[] = $val; 7 } 8 9 var_dump($intersaction); 10 ?>
输出
array(3) { [0]=> int(1) [1]=> int(3) [2]=> int(9) }