@@ -159,7 +159,7 @@ public static function keyExists($key, array $arr): bool
159159 */
160160 public static function valueToLower (array $ arr ): array
161161 {
162- return self ::changeValueCase ($ arr , 0 );
162+ return self ::changeValueCase ($ arr , false );
163163 }
164164
165165 /**
@@ -175,12 +175,12 @@ public static function valueToUpper(array $arr): array
175175 /**
176176 * 将数组中的值全部转为大写或小写
177177 *
178- * @param array $arr
179- * @param int $toUpper 1 值大写 0 值小写
178+ * @param array|iterable $arr
179+ * @param bool $toUpper
180180 *
181181 * @return array
182182 */
183- public static function changeValueCase ($ arr , $ toUpper = 1 ): array
183+ public static function changeValueCase ($ arr , bool $ toUpper = true ): array
184184 {
185185 $ function = $ toUpper ? 'strtoupper ' : 'strtolower ' ;
186186 $ newArr = []; //格式化后的数组
@@ -248,7 +248,7 @@ public static function valueExistsOne($check, array $sampleArr): bool
248248 *
249249 * @return bool | string 不存在的会返回 检查到的 字段,判断时 请使用 ArrHelper::existsAll($need,$arr)===true 来验证是否全存在
250250 */
251- public static function existsAll ($ need , $ arr , $ type = false )
251+ public static function existsAll ($ need , $ arr , bool $ type = false )
252252 {
253253 if (is_array ($ need )) {
254254 foreach ((array )$ need as $ v ) {
@@ -274,12 +274,12 @@ public static function existsAll($need, $arr, $type = false)
274274 * 有一个存在就返回 true 都不存在 return false
275275 *
276276 * @param string|array $need
277- * @param array $arr 只能检查一维数组
277+ * @param array|iterable $arr 只能检查一维数组
278278 * @param bool $type 是否同时验证类型
279279 *
280280 * @return bool
281281 */
282- public static function existsOne ($ need , $ arr , $ type = false ): bool
282+ public static function existsOne ($ need , $ arr , bool $ type = false ): bool
283283 {
284284 if (is_array ($ need )) {
285285 foreach ((array )$ need as $ v ) {
@@ -309,28 +309,59 @@ public static function existsOne($need, $arr, $type = false): bool
309309 /**
310310 * get key Max Width
311311 *
312- * @param array $data
313- * [
312+ * ```php
313+ * $data = [
314314 * 'key1' => 'value1',
315315 * 'key2-test' => 'value2',
316- * ]
317- * @param bool $expectInt
316+ * ]
317+ * ```
318+ *
319+ * @param array $data
320+ * @param bool $excludeInt
318321 *
319322 * @return int
320323 */
321- public static function getKeyMaxWidth (array $ data , $ expectInt = true ): int
324+ public static function getKeyMaxWidth (array $ data , bool $ excludeInt = true ): int
322325 {
323- $ keyMaxWidth = 0 ;
324-
326+ $ maxWidth = 0 ;
325327 foreach ($ data as $ key => $ value ) {
326328 // key is not a integer
327- if (!$ expectInt || !is_numeric ($ key )) {
328- $ width = mb_strlen ($ key , 'UTF-8 ' );
329- $ keyMaxWidth = $ width > $ keyMaxWidth ? $ width : $ keyMaxWidth ;
329+ if (!$ excludeInt || !is_numeric ($ key )) {
330+ $ width = mb_strlen ($ key , 'UTF-8 ' );
331+ $ maxWidth = $ width > $ maxWidth ? $ width : $ maxWidth ;
332+ }
333+ }
334+
335+ return $ maxWidth ;
336+ }
337+
338+ /**
339+ * get max width
340+ *
341+ * ```php
342+ * $keys = [
343+ * 'key1',
344+ * 'key2-test',
345+ * ]
346+ * ```
347+ *
348+ * @param array $keys
349+ * @param bool $excludeInt
350+ *
351+ * @return int
352+ */
353+ public static function getMaxWidth (array $ keys , bool $ excludeInt = true ): int
354+ {
355+ $ maxWidth = 0 ;
356+ foreach ($ keys as $ key ) {
357+ // key is not a integer
358+ if (!$ excludeInt || !is_numeric ($ key )) {
359+ $ keyWidth = mb_strlen ($ key , 'UTF-8 ' );
360+ $ maxWidth = $ keyWidth > $ maxWidth ? $ keyWidth : $ maxWidth ;
330361 }
331362 }
332363
333- return $ keyMaxWidth ;
364+ return $ maxWidth ;
334365 }
335366
336367 ////////////////////////////////////////////////////////////
@@ -606,8 +637,8 @@ public static function remove(array &$arr, $key, $default = null)
606637 /**
607638 * Get a value from the array, and remove it.
608639 *
609- * @param array $array
610- * @param string $key
640+ * @param array|ArrayAccess $array
641+ * @param string|int $key
611642 * @param mixed $default
612643 *
613644 * @return mixed
0 commit comments