Skip to content

Commit 3564a59

Browse files
authored
Introducing Arr::hasAll (#863)
* Introducing `Arr::hasAll` * style(Arr): 格式化 hasAll 方法的参数注释 * Remove phpdoc --------- Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com>
1 parent c941ad5 commit 3564a59

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

output/Hyperf/Collection/Arr.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ public static function from($items)
6868
{
6969
}
7070

71+
/**
72+
* Determine if all keys exist in an array using "dot" notation.
73+
*
74+
* @param ArrayAccess|array $array
75+
* @param string|array $keys
76+
* @return bool
77+
*/
78+
public static function hasAll($array, $keys)
79+
{
80+
}
81+
7182
/**
7283
* Get an integer item from an array using "dot" notation.
7384
* @return int

src/ArrMixin.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,25 @@ public function from()
101101
};
102102
}
103103

104+
public static function hasAll()
105+
{
106+
return function ($array, $keys) {
107+
$keys = (array) $keys;
108+
109+
if (! $array || $keys === []) {
110+
return false;
111+
}
112+
113+
foreach ($keys as $key) {
114+
if (! static::has($array, $key)) {
115+
return false;
116+
}
117+
}
118+
119+
return true;
120+
};
121+
}
122+
104123
/**
105124
* Get an integer item from an array using "dot" notation.
106125
*/

0 commit comments

Comments
 (0)