3v4l.org

run code in 300+ PHP versions simultaneously
<?php $haystack = [7, 6, 14, 15, 8, 0, 1, 4, 5, 9]; $needles = [ [3, 2, 7, 6], [7, 6, 15, 14], [15,14,11,10], [1,3,5,7], [5,7,13,15], [13,15,9,11], [0,1,4,5], [4,5,12,13], ]; // assuming all needle values are unique and all values in each haystacks subarray are unique function getIndexOfMatchingArrays(array $needles, array $haystack) { if (!$haystack) { return -1; } foreach ($needles as $index => $needle) { if ($needle === array_intersect($needle, $haystack)) { $fullMatch[] = $index; } } return $fullMatch ?? -1; } var_export( getIndexOfMatchingArrays($needles, $haystack) );

preferences:
54.58 ms | 402 KiB | 5 Q