@@ -197,7 +197,7 @@ public static function sortDesc(
197197 bool $ preserveKeys = false ,
198198 int $ flags = \SORT_REGULAR
199199 ): array {
200- if (! $ preserveKeys ) {
200+ if ($ preserveKeys ) {
201201 arsort ($ array , $ flags );
202202 return $ array ;
203203 }
@@ -560,8 +560,8 @@ public static function implode(string $separator, iterable $array): string
560560 }
561561
562562 /**
563- * Remove whitespace from the beginning and end of each value in an array
564- * of strings and Stringables before optionally removing empty strings
563+ * Remove whitespace from the beginning and end of each value in an array of
564+ * strings and Stringables before optionally removing empty strings
565565 *
566566 * @template TKey of array-key
567567 * @template TValue of int|float|string|bool|Stringable|null
@@ -570,7 +570,7 @@ public static function implode(string $separator, iterable $array): string
570570 * @param string|null $characters Optionally specify characters to remove
571571 * instead of whitespace.
572572 *
573- * @return array<TKey,string>
573+ * @return ($removeEmpty is false ? array<TKey,string> : list<string>)
574574 */
575575 public static function trim (
576576 iterable $ array ,
@@ -582,7 +582,10 @@ public static function trim(
582582 $ characters === null
583583 ? trim ((string ) $ value )
584584 : trim ((string ) $ value , $ characters );
585- if ($ removeEmpty && $ value === '' ) {
585+ if ($ removeEmpty ) {
586+ if ($ value !== '' ) {
587+ $ trimmed [] = $ value ;
588+ }
586589 continue ;
587590 }
588591 $ trimmed [$ key ] = $ value ;
@@ -641,7 +644,7 @@ public static function upper(iterable $array): array
641644 public static function toScalars (iterable $ array ): array
642645 {
643646 foreach ($ array as $ key => $ value ) {
644- if (!is_scalar ($ value )) {
647+ if ($ value !== null && !is_scalar ($ value )) {
645648 if (Test::isStringable ($ value )) {
646649 $ value = (string ) $ value ;
647650 } elseif ($ value instanceof Jsonable) {
0 commit comments