<?php
function anyKeyExists($haystack, $needles) {
foreach ($needles as $needle) {
if (isset($haystack[$needle])) {
return true;
}
}
return false;
}
$array = [
"keyA" => 1,
"keyB" => 2,
"keyC" => 3
];
echo "noMatch: " , (int)anyKeyExists($array, ['keyD', 'keyF']) , "\n";
echo "oneMatch: " , anyKeyExists($array, ['keyB', 'keyD']) , "\n";
echo "twoMatches: " , anyKeyExists($array, ['keyA', 'keyC']) , "\n";
- Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
- noMatch: 0
oneMatch: 1
twoMatches: 1
preferences:
137.45 ms | 410 KiB | 5 Q