2012-04-25 10 views
0

가능한 중복 넣어 :
PHP compare arrayPHP에서 두 배열을 비교하고 밖으로 결과를

내가 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 –

답변

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