1212use ArrayAccess ;
1313use ArrayObject ;
1414use stdClass ;
15+ use Toolkit \Stdlib \Helper \DataHelper ;
1516use Traversable ;
1617use function array_change_key_case ;
1718use function array_diff ;
2930use function explode ;
3031use function get_class ;
3132use function gettype ;
33+ use function implode ;
3234use function in_array ;
3335use function is_array ;
3436use function is_numeric ;
@@ -212,7 +214,7 @@ public static function valueExistsAll($check, array $sampleArr): bool
212214 // 以逗号分隔的会被拆开,组成数组
213215 if (is_string ($ check )) {
214216 $ check = trim ($ check , ', ' );
215- $ check = strpos ($ check , ', ' ) !== false ? ( array ) explode (', ' , $ check ) : [$ check ];
217+ $ check = str_contains ($ check , ', ' ) ? explode (', ' , $ check ) : [$ check ];
216218 }
217219
218220 return !array_diff ((array )$ check , $ sampleArr );
@@ -232,7 +234,7 @@ public static function valueExistsOne($check, array $sampleArr): bool
232234 // 以逗号分隔的会被拆开,组成数组
233235 if (is_string ($ check )) {
234236 $ check = trim ($ check , ', ' );
235- $ check = strpos ($ check , ', ' ) !== false ? ( array ) explode (', ' , $ check ) : [$ check ];
237+ $ check = str_contains ($ check , ', ' ) ? explode (', ' , $ check ) : [$ check ];
236238 }
237239
238240 return (bool )array_intersect ((array )$ check , $ sampleArr );
@@ -254,7 +256,7 @@ public static function existsAll($need, $arr, bool $type = false)
254256 foreach ((array )$ need as $ v ) {
255257 self ::existsAll ($ v , $ arr , $ type );
256258 }
257- } elseif (strpos ($ need , ', ' ) !== false ) {
259+ } elseif (str_contains ($ need , ', ' )) {
258260 $ need = explode (', ' , $ need );
259261 self ::existsAll ($ need , $ arr , $ type );
260262 } else {
@@ -289,7 +291,7 @@ public static function existsOne($need, $arr, bool $type = false): bool
289291 }
290292 }
291293 } else {
292- if (strpos ($ need , ', ' ) !== false ) {
294+ if (str_contains ($ need , ', ' )) {
293295 $ need = explode (', ' , $ need );
294296
295297 return self ::existsOne ($ need , $ arr , $ type );
@@ -514,7 +516,7 @@ public static function flatten(array $array, int $depth = INF): array
514516 *
515517 * @return void
516518 */
517- public static function forget (&$ array , $ keys ): void
519+ public static function forget (array &$ array , $ keys ): void
518520 {
519521 $ original = &$ array ;
520522 $ keys = (array )$ keys ;
@@ -787,7 +789,7 @@ public static function toStringNoKey(
787789 *
788790 * @return string
789791 */
790- public static function toFormatString ($ array , int $ length = 400 ): string
792+ public static function toFormatString (array $ array , int $ length = 400 ): string
791793 {
792794 $ string = var_export ($ array , true );
793795
@@ -834,7 +836,23 @@ public static function toLimitOut($array): array
834836 }
835837
836838 // $num++;
837-
838839 return $ array ;
839840 }
841+
842+ /**
843+ * @param array $data
844+ * @param string $kvSep
845+ * @param string $lineSep
846+ *
847+ * @return string
848+ */
849+ public static function toKVString (array $ data , string $ kvSep = '= ' , string $ lineSep = "\n" ): string
850+ {
851+ $ lines = [];
852+ foreach ($ data as $ key => $ val ) {
853+ $ lines = $ key . $ kvSep . DataHelper::toString ($ val );
854+ }
855+
856+ return implode ($ lineSep , $ lines );
857+ }
840858}
0 commit comments