Feature #26485
closedNatural sort with t3lib_div::naturalKeySortRecursive()
100%
Description
This function uses strcasecmp() function to sort the array. But the real natural sorting should be implemened with strnatcasecmp().
So, the proposition is to change strcasecmp to strnatcasecmp in uksort second parameter. It will help to order complex array with numeric indexes.
Original function code :
/** * Sorts an array by key recursive - uses natural sort order (aAbB-zZ) * * @param array $array array to be sorted recursively, passed by reference * @return boolean TRUE if param is an array */ public static function naturalKeySortRecursive(&$array) { if (!is_array($array)) { return FALSE; } uksort($array, 'strcasecmp'); foreach ($array as $key => $value) { self::naturalKeySortRecursive($array[$key]); } return TRUE; }
Thanks You for the attention.
Updated by Markus Klein over 13 years ago
Do you use this method in your own code?
The core uses this method only in sysext lowlevel. It doesn't make any difference there.
Updated by Oliver Hader over 13 years ago
- Status changed from New to Under Review
Updated by Oliver Hader over 13 years ago
- Status changed from Under Review to New
Updated by Mr. Hudson over 13 years ago
Patch set 1 of change Ia9cd9a36da2bc0b6111a025e73b5bf8d26319c08 has been pushed to the review server.
It is available at http://review.typo3.org/1787
Updated by Mr. Hudson over 13 years ago
Patch set 2 of change Ia9cd9a36da2bc0b6111a025e73b5bf8d26319c08 has been pushed to the review server.
It is available at http://review.typo3.org/1787
Updated by Fedir RYKHTIK over 13 years ago
This method is quite handy, when You need to sort complex array of TS. Instead of reinventing own sorting API, it's much better to use native core methods.
Example of TS array :
... 10 = a 1000.2 = bbbb 100 = aa 20 = bb 1000 = aaa 1000.10 = aaaa 2 = b ...
To sort such array You need to do exactly what this method should do : recursive natural sort by array keys.
Updated by Mr. Hudson over 13 years ago
Patch set 1 of change Ic378215707dfa0b20a198f82230afd56f1681934 has been pushed to the review server.
It is available at http://review.typo3.org/2109
Updated by Mr. Hudson about 13 years ago
Patch set 3 of change Ia9cd9a36da2bc0b6111a025e73b5bf8d26319c08 has been pushed to the review server.
It is available at http://review.typo3.org/1787
Updated by Mr. Hudson about 13 years ago
Patch set 4 of change Ia9cd9a36da2bc0b6111a025e73b5bf8d26319c08 has been pushed to the review server.
It is available at http://review.typo3.org/1787
Updated by Mr. Hudson about 13 years ago
Patch set 2 of change Ic378215707dfa0b20a198f82230afd56f1681934 has been pushed to the review server.
It is available at http://review.typo3.org/2109
Updated by Mr. Hudson about 13 years ago
Patch set 3 of change Ic378215707dfa0b20a198f82230afd56f1681934 has been pushed to the review server.
It is available at http://review.typo3.org/2109
Updated by Markus Klein about 13 years ago
- Status changed from New to Resolved
- % Done changed from 0 to 100
Applied in changeset 2d16a5bd419864809c9e8c174aeba2aaba74229a.
Updated by Riccardo De Contardi almost 7 years ago
- Status changed from Resolved to Closed