I liked this question and I liked the different solutions. I know I'm late to the party but here is my attempt at it. I don't know how it compares in terms of cost with big data sets but this should be quite robust.
My attempt just iterates across each element and then creates a second array of the same size as the searched array and then does a comparison check at the end.
Code:
function checkArray($a, $b){
$test = FALSE;
for($i = 0; $i < count($a); $i++){
for($j = 0; $j < count($b); $j++){
$array[] = $a[$i + $j];
}
if($array == $b){
$test = TRUE;
break;
}
unset($array);
}
return $test;
}
$sample = ['A', 'B', 'C', 'D', 'E', 'F'];
$match = ['B', 'C', 'D'];
echo checkArray($sample, $match) ? "true\n" : "false\n"; //True
$match = ['C', 'D', 'B'];
echo checkArray($sample, $match) ? "true\n" : "false\n"; //False
$match = ['B', 'D', 'E'];
echo checkArray($sample, $match) ? "true\n" : "false\n"; //False
$match = ['A', 'B', 'C'];
echo checkArray($sample, $match) ? "true\n" : "false\n"; //True
$match = ['A'];
echo checkArray($sample, $match) ? "true\n" : "false\n"; //True
$match = ['F'];
echo checkArray($sample, $match) ? "true\n" : "false\n";//True
$sample = ['A', 'C', 'C', 'D', 'E', 'F'];
$match = ['C', 'D', 'E'];
echo checkArray($sample, $match) ? "true\n" : "false\n";//True
$sample = ['C', 'D', 'E'];
$match = ['A', 'C', 'C', 'D', 'E', 'F'];
echo checkArray($sample, $match) ? "true\n" : "false\n";//False
This will output:
true
false
false
true
true
true
true
false