<?php
function array_key_match($target, $match) {
$targetKeys = array_keys($target);
$diff = array_diff($target, $match);
return ($diff == array_diff($diff, $match));
}
function test($target, $match, $expect) {
return preg_replace('/\n/', '', sprintf(
"Target %s, Match %s: %s\n",
var_dump($target, true),
var_dump($match, true),
(array_key_match($target, $match) == $expect)
? 'true'
: 'false'
));
}
print test([1, 2, 3, 4, 5], [2, 3], true);
print test(['a', 'b', 'c'], ['c', 'b'], true);
print test([1, 2, 3, 4, 5], [4, 5, 6], false);
preferences:
44.8 ms | 402 KiB | 5 Q