Project

General

Profile

Actions

Feature #26485

closed

Natural sort with t3lib_div::naturalKeySortRecursive()

Added by Fedir RYKHTIK about 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

Also available in: Atom PDF