Skip to content

Commit cf0497e

Browse files
committed
Add hasAll method from the Laravel framework
1 parent b9b64d2 commit cf0497e

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/Arrayer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* @method self flatten(int $depth = INF)
2222
* @method mixed get(string|int|null $key, mixed $default = null)
2323
* @method bool has(string|array $keys)
24+
* @method bool hasAll(\ArrayAccess|array $array, string|array $keys)
2425
* @method bool hasAny(string|array $keys)
2526
* @method bool isAssoc()
2627
* @method bool isList()

src/Traits/LaravelArrTrait.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,31 @@ public static function has($array, $keys)
389389
return true;
390390
}
391391

392+
393+
/**
394+
* Determine if all keys exist in an array using "dot" notation.
395+
*
396+
* @param \ArrayAccess|array $array
397+
* @param string|array $keys
398+
* @return bool
399+
*/
400+
public static function hasAll($array, $keys)
401+
{
402+
$keys = (array) $keys;
403+
404+
if (!$array || $keys === []) {
405+
return false;
406+
}
407+
408+
foreach ($keys as $key) {
409+
if (!static::has($array, $key)) {
410+
return false;
411+
}
412+
}
413+
414+
return true;
415+
}
416+
392417
/**
393418
* Determine if any of the keys exist in an array using "dot" notation.
394419
*

0 commit comments

Comments
 (0)