Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions system/Helpers/Array/ArrayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int|list<int|string>|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);
});
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This file is part of CodeIgniter 4 framework.
*
Expand Down