<?php
function array_key_match($target, $match) {
$targetKeys = array_keys($target);
$diff = array_diff($target, $match);
return ($diff == array_diff($diff, $match));
}
print_r(array_diff([1, 2, 3, 4], [1, 4]));
function test($target, $match, $expect) {
return sprintf(
"Target %s, Match %s: %s\n",
var_export($target, true),
var_export($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:
36.08 ms | 402 KiB | 5 Q