Created
May 1, 2017 05:47
-
-
Save violetyk/870ecd5eac7bd7d6ccab58e1b711c5cc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function f($in, $required) { | |
$keys = array_keys(array_intersect_key(($in), array_flip($required))); | |
sort($keys); | |
sort($required); | |
return $keys === $required; | |
} | |
$required = array('key1', 'key2'); | |
$in1 = array( | |
'key2' => 200, | |
'key1' => 100, | |
'key3' => 333, | |
); | |
$in2 = array( | |
'key1' => 100, | |
'key3' => 333, | |
); | |
$result = f($in1, $required); | |
var_dump($result); | |
$result = f($in2, $required); | |
var_dump($result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment