@@ -56,7 +56,7 @@ public static function toIterator($array): \Traversable
56
56
/**
57
57
* array data to object
58
58
* @param array|\Traversable $array
59
- * @param string $class
59
+ * @param string $class
60
60
* @return mixed
61
61
*/
62
62
public static function toObject ($ array , $ class = \stdClass::class)
@@ -78,8 +78,8 @@ public static function toObject($array, $class = \stdClass::class)
78
78
79
79
/**
80
80
* Get Multi - 获取多个, 可以设置默认值
81
- * @param array $data array data
82
- * @param array $needKeys
81
+ * @param array $data array data
82
+ * @param array $needKeys
83
83
* $needKeys = [
84
84
* 'name',
85
85
* 'password',
@@ -125,7 +125,7 @@ public static function gets(array &$data, array $needKeys = [], $unsetKey = fals
125
125
/**
126
126
* 递归合并两个多维数组,后面的值将会递归覆盖原来的值
127
127
* @param array|null $src
128
- * @param array $new
128
+ * @param array $new
129
129
* @return array
130
130
*/
131
131
public static function merge ($ src , array $ new ): array
@@ -210,7 +210,7 @@ public static function valueTrim(array $data)
210
210
/**
211
211
* 不区分大小写检测数据键名是否存在
212
212
* @param int|string $key
213
- * @param array $arr
213
+ * @param array $arr
214
214
* @return bool
215
215
*/
216
216
public static function keyExists ($ key , array $ arr ): bool
@@ -239,13 +239,13 @@ public static function valueToUpper(array $arr): array
239
239
/**
240
240
* 将数组中的值全部转为大写或小写
241
241
* @param array $arr
242
- * @param int $toUpper 1 值大写 0 值小写
242
+ * @param int $toUpper 1 值大写 0 值小写
243
243
* @return array
244
244
*/
245
245
public static function changeValueCase ($ arr , $ toUpper = 1 ): array
246
246
{
247
247
$ function = $ toUpper ? 'strtoupper ' : 'strtolower ' ;
248
- $ newArr = array () ; //格式化后的数组
248
+ $ newArr = [] ; //格式化后的数组
249
249
250
250
foreach ($ arr as $ k => $ v ) {
251
251
if (\is_array ($ v )) {
@@ -263,7 +263,7 @@ public static function changeValueCase($arr, $toUpper = 1): array
263
263
* ******* 检查 一个或多个值是否全部存在数组中 *******
264
264
* 有一个不存在即返回 false
265
265
* @param string|array $check
266
- * @param array $sampleArr 只能检查一维数组
266
+ * @param array $sampleArr 只能检查一维数组
267
267
* 注: 不分类型, 区分大小写 2 == '2' ‘a' != 'A'
268
268
* @return bool
269
269
*/
@@ -272,7 +272,7 @@ public static function valueExistsAll($check, array $sampleArr): bool
272
272
// 以逗号分隔的会被拆开,组成数组
273
273
if (\is_string ($ check )) {
274
274
$ check = trim ($ check , ', ' );
275
- $ check = strpos ($ check , ', ' ) !== false ? explode (', ' , $ check ) : array ( $ check) ;
275
+ $ check = strpos ($ check , ', ' ) !== false ? explode (', ' , $ check ) : [ $ check] ;
276
276
}
277
277
278
278
return !array_diff ((array )$ check , $ sampleArr );
@@ -282,15 +282,15 @@ public static function valueExistsAll($check, array $sampleArr): bool
282
282
* ******* 检查 一个或多个值是否存在数组中 *******
283
283
* 有一个存在就返回 true 都不存在 return false
284
284
* @param string|array $check
285
- * @param array $sampleArr 只能检查一维数组
285
+ * @param array $sampleArr 只能检查一维数组
286
286
* @return bool
287
287
*/
288
288
public static function valueExistsOne ($ check , array $ sampleArr ): bool
289
289
{
290
290
// 以逗号分隔的会被拆开,组成数组
291
291
if (\is_string ($ check )) {
292
292
$ check = trim ($ check , ', ' );
293
- $ check = strpos ($ check , ', ' ) !== false ? explode (', ' , $ check ) : array ( $ check) ;
293
+ $ check = strpos ($ check , ', ' ) !== false ? explode (', ' , $ check ) : [ $ check] ;
294
294
}
295
295
296
296
return (bool )array_intersect ((array )$ check , $ sampleArr );
@@ -300,8 +300,8 @@ public static function valueExistsOne($check, array $sampleArr): bool
300
300
* ******* 不区分大小写,检查 一个或多个值是否 全存在数组中 *******
301
301
* 有一个不存在即返回 false
302
302
* @param string|array $need
303
- * @param array $arr 只能检查一维数组
304
- * @param bool $type 是否同时验证类型
303
+ * @param array $arr 只能检查一维数组
304
+ * @param bool $type 是否同时验证类型
305
305
* @return bool | string 不存在的会返回 检查到的 字段,判断时 请使用 ArrHelper::existsAll($need,$arr)===true 来验证是否全存在
306
306
*/
307
307
public static function existsAll ($ need , $ arr , $ type = false )
@@ -334,8 +334,8 @@ public static function existsAll($need, $arr, $type = false)
334
334
* ******* 不区分大小写,检查 一个或多个值是否存在数组中 *******
335
335
* 有一个存在就返回 true 都不存在 return false
336
336
* @param string|array $need
337
- * @param array $arr 只能检查一维数组
338
- * @param bool $type 是否同时验证类型
337
+ * @param array $arr 只能检查一维数组
338
+ * @param bool $type 是否同时验证类型
339
339
* @return bool
340
340
*/
341
341
public static function existsOne ($ need , $ arr , $ type = false ): bool
@@ -372,7 +372,7 @@ public static function existsOne($need, $arr, $type = false): bool
372
372
* 'key1' => 'value1',
373
373
* 'key2-test' => 'value2',
374
374
* ]
375
- * @param bool $expectInt
375
+ * @param bool $expectInt
376
376
* @return int
377
377
*/
378
378
public static function getKeyMaxWidth (array $ data , $ expectInt = true ): int
@@ -395,9 +395,9 @@ public static function getKeyMaxWidth(array $data, $expectInt = true): int
395
395
* Get data from array or object by path.
396
396
* Example: `DataCollector::getByPath($array, 'foo.bar.yoo')` equals to $array['foo']['bar']['yoo'].
397
397
* @param array|\ArrayAccess $data An array or object to get value.
398
- * @param mixed $path The key path.
399
- * @param mixed $default
400
- * @param string $separator Separator of paths.
398
+ * @param mixed $path The key path.
399
+ * @param mixed $default
400
+ * @param string $separator Separator of paths.
401
401
* @return mixed Found value, null if not exists.
402
402
*/
403
403
public static function getByPath ($ data , string $ path , $ default = null , string $ separator = '. ' )
@@ -433,9 +433,9 @@ public static function getByPath($data, string $path, $default = null, string $s
433
433
/**
434
434
* setByPath
435
435
* @param array|\ArrayAccess &$data
436
- * @param string $path
437
- * @param mixed $value
438
- * @param string $separator
436
+ * @param string $path
437
+ * @param mixed $value
438
+ * @param string $separator
439
439
*/
440
440
public static function setByPath (&$ data , string $ path , $ value , string $ separator = '. ' )
441
441
{
@@ -460,7 +460,7 @@ public static function setByPath(&$data, string $path, $value, string $separator
460
460
} else {
461
461
// If a node is value but path is not go to the end, we replace this value as a new store.
462
462
// Then next node can insert new value to this store.
463
- $ dataTmp = array () ;
463
+ $ dataTmp = [] ;
464
464
}
465
465
}
466
466
@@ -522,7 +522,7 @@ public static function divide($array): array
522
522
523
523
/**
524
524
* Flatten a multi-dimensional associative array with dots.
525
- * @param array $array
525
+ * @param array $array
526
526
* @param string $prepend
527
527
* @return array
528
528
*/
@@ -543,7 +543,7 @@ public static function dot($array, $prepend = ''): array
543
543
544
544
/**
545
545
* Get all of the given array except for a specified array of items.
546
- * @param array $array
546
+ * @param array $array
547
547
* @param array|string $keys
548
548
* @return array
549
549
*/
@@ -557,7 +557,7 @@ public static function except($array, $keys): array
557
557
/**
558
558
* Determine if the given key exists in the provided array.
559
559
* @param \ArrayAccess|array $array
560
- * @param string|int $key
560
+ * @param string|int $key
561
561
* @return bool
562
562
*/
563
563
public static function exists ($ array , $ key ): bool
@@ -571,9 +571,9 @@ public static function exists($array, $key): bool
571
571
572
572
/**
573
573
* Add an element to an array using "dot" notation if it doesn't exist.
574
- * @param array $array
574
+ * @param array $array
575
575
* @param string $key
576
- * @param mixed $value
576
+ * @param mixed $value
577
577
* @return array
578
578
*/
579
579
public static function add ($ array , $ key , $ value ): array
@@ -588,8 +588,8 @@ public static function add($array, $key, $value): array
588
588
/**
589
589
* Get an item from an array using "dot" notation.
590
590
* @param \ArrayAccess|array $array
591
- * @param string $key
592
- * @param mixed $default
591
+ * @param string $key
592
+ * @param mixed $default
593
593
* @return mixed
594
594
*/
595
595
public static function get ($ array , $ key , $ default = null )
@@ -620,9 +620,9 @@ public static function get($array, $key, $default = null)
620
620
/**
621
621
* Set an array item to a given value using "dot" notation.
622
622
* If no key is given to the method, the entire array will be replaced.
623
- * @param array $array
623
+ * @param array $array
624
624
* @param string $key
625
- * @param mixed $value
625
+ * @param mixed $value
626
626
* @return array
627
627
*/
628
628
public static function set (&$ array , $ key , $ value ): array
@@ -653,7 +653,7 @@ public static function set(&$array, $key, $value): array
653
653
/**
654
654
* Flatten a multi-dimensional array into a single level.
655
655
* @param array $array
656
- * @param int $depth
656
+ * @param int $depth
657
657
* @return array
658
658
*/
659
659
public static function flatten ($ array , $ depth = INF ): array
@@ -675,7 +675,7 @@ public static function flatten($array, $depth = INF): array
675
675
676
676
/**
677
677
* Remove one or many array items from a given array using "dot" notation.
678
- * @param array $array
678
+ * @param array $array
679
679
* @param array|string $keys
680
680
* @return void
681
681
*/
@@ -718,7 +718,7 @@ public static function forget(&$array, $keys)
718
718
/**
719
719
* Check if an item or items exist in an array using "dot" notation.
720
720
* @param \ArrayAccess|array $array
721
- * @param string|array $keys
721
+ * @param string|array $keys
722
722
* @return bool
723
723
*/
724
724
public static function has ($ array , $ keys ): bool
@@ -778,8 +778,8 @@ public static function prepend($array, $value, $key = null): array
778
778
/**
779
779
* remove the $key of the $arr, and return value.
780
780
* @param string $key
781
- * @param array $arr
782
- * @param mixed $default
781
+ * @param array $arr
782
+ * @param mixed $default
783
783
* @return mixed
784
784
*/
785
785
public static function remove (&$ arr , $ key , $ default = null )
@@ -796,9 +796,9 @@ public static function remove(&$arr, $key, $default = null)
796
796
797
797
/**
798
798
* Get a value from the array, and remove it.
799
- * @param array $array
799
+ * @param array $array
800
800
* @param string $key
801
- * @param mixed $default
801
+ * @param mixed $default
802
802
* @return mixed
803
803
*/
804
804
public static function pull (&$ array , $ key , $ default = null )
@@ -812,7 +812,7 @@ public static function pull(&$array, $key, $default = null)
812
812
813
813
/**
814
814
* Get a subset of the items from the given array.
815
- * @param array $array
815
+ * @param array $array
816
816
* @param array|string $keys
817
817
* @return array
818
818
*/
@@ -835,7 +835,7 @@ public static function shuffle($array): array
835
835
836
836
/**
837
837
* Filter the array using the given callback.
838
- * @param array $array
838
+ * @param array $array
839
839
* @param callable $callback
840
840
* @return array
841
841
*/
@@ -860,13 +860,13 @@ public static function wrap($value): array
860
860
861
861
/**
862
862
* array 递归 转换成 字符串
863
- * @param array $array [大于1200字符 strlen($string)>1200
864
- * @param int $length
863
+ * @param array $array [大于1200字符 strlen($string)>1200
864
+ * @param int $length
865
865
* @param array|int $cycles [至多循环六次 $num >= 6
866
- * @param bool $showKey
867
- * @param bool $addMark
868
- * @param string $separator
869
- * @param string $string
866
+ * @param bool $showKey
867
+ * @param bool $addMark
868
+ * @param string $separator
869
+ * @param string $string
870
870
* @return string
871
871
*/
872
872
public static function toString (
@@ -877,8 +877,7 @@ public static function toString(
877
877
$ addMark = false ,
878
878
$ separator = ', ' ,
879
879
$ string = ''
880
- ): string
881
- {
880
+ ): string {
882
881
if (!\is_array ($ array ) || empty ($ array )) {
883
882
return '' ;
884
883
}
@@ -923,14 +922,13 @@ public static function toStringNoKey(
923
922
$ showKey = false ,
924
923
$ addMark = true ,
925
924
$ separator = ', '
926
- ): string
927
- {
925
+ ): string {
928
926
return static ::toString ($ array , $ length , $ cycles , $ showKey , $ addMark , $ separator );
929
927
}
930
928
931
929
/**
932
930
* @param array $array
933
- * @param int $length
931
+ * @param int $length
934
932
* @return mixed|null|string|string[]
935
933
*/
936
934
public static function toFormatString ($ array , $ length = 400 )
0 commit comments