diff --git a/system/Helpers/Array/ArrayHelper.php b/system/Helpers/Array/ArrayHelper.php index d47ae94c5279..cadac28d6c29 100644 --- a/system/Helpers/Array/ArrayHelper.php +++ b/system/Helpers/Array/ArrayHelper.php @@ -306,16 +306,17 @@ public static function recursiveCount(array $array, int $counter = 0): int * Sorts array values in natural order * If the value is an array, you need to specify the $sortByIndex of the key to sort * - * @param int|string|null $sortByIndex + * @param list|string> $array + * @param int|string|null $sortByIndex */ public static function sortValuesByNatural(array &$array, $sortByIndex = null): bool { return usort($array, static function ($currentValue, $nextValue) use ($sortByIndex) { if ($sortByIndex !== null) { - return strnatcmp($currentValue[$sortByIndex], $nextValue[$sortByIndex]); + return strnatcmp((string) $currentValue[$sortByIndex], (string) $nextValue[$sortByIndex]); } - return strnatcmp($currentValue, $nextValue); + return strnatcmp((string) $currentValue, (string) $nextValue); }); } } diff --git a/tests/system/Helpers/Array/ArrayHelperSortValuesByNaturalTest.php b/tests/system/Helpers/Array/ArrayHelperSortValuesByNaturalTest.php index 312eb0853c9d..861d6ede713f 100644 --- a/tests/system/Helpers/Array/ArrayHelperSortValuesByNaturalTest.php +++ b/tests/system/Helpers/Array/ArrayHelperSortValuesByNaturalTest.php @@ -1,5 +1,7 @@