forked from maciejczyzewski/bottomline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hasKeys.php
41 lines (39 loc) · 938 Bytes
/
hasKeys.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
namespace collections;
/**
* Returns true if `$input` contains all requested $keys. If `$strict` is `true`
* it also checks if `$input` exclusively contains the given `$keys`.
*
* **Usage**
*
* ```php
* __::hasKeys(['foo' => 'bar', 'foz' => 'baz'], ['foo', 'foz']);
* ```
*
* **Result**
*
* ```
* true
* ```
*
* @param array|object $collection of key values pairs
* @param array $keys collection of keys to look for
* @param bool $strict to exclusively check
*
* @return bool
*/
function hasKeys($collection = [], array $keys = [], $strict = false)
{
$keyCount = \count($keys);
if ($strict && \count($collection) !== $keyCount) {
return false;
}
return \__::every(
\__::map($keys, function ($key) use ($collection) {
return \__::has($collection, $key);
}),
function ($v) {
return $v === true;
}
);
}