2010-02-16 78 views

回答

11
<?php 

$arr = array_intersect(array('a', 'b', 'c', 'd'), 
         array('c', 'd', 'e', 'f')); 

print_r(array_values($arr)); 
12

看到http://docs.php.net/array_intersect

array_intersect()返回一個包含存在於所有的參數的ARRAY1的所有值的數組。請注意,鍵被保留。
$a = array('a','b','c','d','e','f','g','h'); 
$b = array('c','d','o','l','p','i','u','y'); 
$c = array_intersect($a, $b); 
var_dump($c); 

打印

array(2) { 
    [2]=> 
    string(1) "c" 
    [3]=> 
    string(1) "d" 
} 
+3

爲了擺脫密鑰,你可以使用'array_values(array_intersect($ a,$ b))' – Marius 2010-02-16 10:24:17

5

嘗試$result = array_intersect($a, $b);

1

使用array_intersect($a,$b) - 喔很多人回答我輸入

相關問題