2012-04-25 69 views
0

可能重複:
PHP compare array在PHP中比較兩個數組和出把結果

我有兩個數組在PHP比較和打印,如果兩個數組都是相同的出來放,但可以以任何方式

$array1=array('a','p','p','l','e'); 
$array2=array('p','a','e','l'); 

--- This must return as success because all of the letters in array1 is there in array2 

$array1=array('a','p','p','l','e','s'); 
$array2=array('p','a','e','l'); 

-- This must return false 

$array1=array('a','p','p','l','e','s'); 
$array1=array('a','p','p','l','e','s'); 
-- This must return true 
訂購元件0

請幫

+2

如何使用搜索? http://stackoverflow.com/questions/901815/php-compare-array – 2012-04-25 10:30:04

回答

1
function compareArrays($array1, $array2) { 
    foreach ($array2 as $currentValue) { 
     if (!in_array($currentValue, $array1) { 
      return false; 
     } 
    } 
    return true; 
}