如果我有:
$hold = array(1, 1, 4); // this will be true
$allArr = array(1, 1, 3, 4, 5);
$containsHold = count(array_intersect($hold, $allArr)) == count($hold);
$ containshold是真的,没关系,但如果我有下一个:
$hold = array(1, 1, 1); // this will be false but it is true
$allArr = array(1, 1, 3, 4, 5);
$containsHold = count(array_intersect($hold, $allArr)) == count($hold);
返回true,但我需要假,因为$ hold包含三个1
答案 0 :(得分:0)
如果我理解正确,你应该计算每个数组的值 而不是比较价值和数量......:
function arrayContainArray($array, $array1){
$c = array_count_values($array);
$c1 = array_count_values($array1);
foreach($c as $k=>$n){
if(!isset($c1[$k]) || $c1[$k]<$n){ return false; }
}
return true;
}
$containsHold = arrayContainArray($hold, $allArr);