我想做以下事情。
假设我有一个数组。
数组A,
-> [0] = A
-> [1] = B
-> [2] = C
我想与多维数组进行比较
-> [0]
[0] = 1
[1] = A
[2] = B
[3] = C
-> [1]
[0] = 2
[1] = B
[2] = C
[3] = A
-> [2]
[0] = 3
[1] = C
[2] = B
[3] = A
我想将第一个数组与多维数组中的内容进行比较。如您所见,多维数组的每个字母组合都附有一个数字。我希望以一种方式进行比较,我可以从数组B中获得相应数量的数组A,假设它们也在数组B中。我怎样才能做到这一点?
答案 0 :(得分:2)
这应该这样做:
public function findSubArray($multiArr, $compArr) {
foreach ($multiArr as $idx => $arr) { //for each sub array
$first = array_shift($arr); //take off the first element and store it
if (count(array_diff($arr, $compArr)) == 0) { //check if the remainder is what you want
return $first; //if so, return the first element
}
} //otherwise loop
}