Issue Feature Closed

#26485Natural sort with t3lib_div::naturalKeySortRecursive()

Fedir RYKHTIK 04/29/11, 11:08 updated 10/24/17, 20:18

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.

Reviews 2