<?php
$A = [3,45,67,8];
$B = [ 1 => [1,6,8],
2 => [5,67,3,4,5,66,6],
3 => [55,56,57,58],
4 => [45,80,81,82]
];
$result = [];
foreach ($A as $needle) {
if ($found = array_keys($B, $needle)) { // something qualified
echo "\nFound: ";
var_export($found);
//$result = array_merge($result, $found); // store the new key(s)
//$B = array_intersect_key($B, $found); // reduce the haystack
}
//echo "Needle: $needle\n";
//var_export($B);
//echo "\n--\n";
//var_export($result);
//echo "\n----\n";
}
preferences:
53.26 ms | 402 KiB | 5 Q