Project

General

Profile

Actions

Feature #26485

closed

Natural sort with t3lib_div::naturalKeySortRecursive()

Added by Fedir RYKHTIK almost 13 years ago. Updated over 6 years ago.

Status:
Closed
Priority:
Could have
Assignee:
-
Category:
Miscellaneous
Target version:
Start date:
2011-04-29
Due date:
% Done:

100%

Estimated time:
0.10 h
PHP Version:
5.0
Tags:
Complexity:
Sprint Focus:

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.

Actions #1

Updated by Markus Klein almost 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.

Actions #2

Updated by Oliver Hader almost 13 years ago

  • Status changed from New to Under Review
Actions #3

Updated by Oliver Hader almost 13 years ago

  • Status changed from Under Review to New
Actions #4

Updated by Mr. Hudson almost 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

Actions #5

Updated by Mr. Hudson almost 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

Actions #6

Updated by Fedir RYKHTIK almost 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.

Actions #7

Updated by Mr. Hudson almost 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

Actions #8

Updated by Mr. Hudson almost 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

Actions #9

Updated by Mr. Hudson almost 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

Actions #10

Updated by Mr. Hudson almost 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

Actions #11

Updated by Mr. Hudson almost 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

Actions #12

Updated by Markus Klein almost 13 years ago

  • Status changed from New to Resolved
  • % Done changed from 0 to 100
Actions #13

Updated by Steffen Gebert almost 13 years ago

  • Target version set to 4.5.4
Actions #14

Updated by Riccardo De Contardi over 6 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF