public static function asort(array &$arr, $sortflag = core_collator::SORT_STRING) {
        if (empty($arr)) {
            // nothing to do
            return true;
        }

        $original = null;

        $casesensitive = (bool)($sortflag & core_collator::CASE_SENSITIVE);
        $sortflag = ($sortflag & ~core_collator::CASE_SENSITIVE);
        if ($sortflag != core_collator::SORT_NATURAL and $sortflag != core_collator::SORT_STRING) {
            $casesensitive = false;
        }

        if (self::ensure_collator_available()) {
            if ($sortflag == core_collator::SORT_NUMERIC) {
                $flag = Collator::SORT_NUMERIC;

            } else if ($sortflag == core_collator::SORT_REGULAR) {
                $flag = Collator::SORT_REGULAR;

            } else {
                $flag = Collator::SORT_STRING;
            }

            if ($sortflag == core_collator::SORT_NATURAL) {
                $original = $arr;
                if ($sortflag == core_collator::SORT_NATURAL) {
                    foreach ($arr as $key => $value) {
                        $arr[$key] = self::naturalise((string)$value);
                    }
                }
            }
            if ($casesensitive) {
                self::$collator->setAttribute(Collator::CASE_FIRST, Collator::UPPER_FIRST);
            } else {
                self::$collator->setAttribute(Collator::CASE_FIRST, Collator::OFF);
            }
            $result = self::$collator->asort($arr, $flag);
            if ($original) {
                self::restore_array($arr, $original);
            }
            return $result;
        }

        // try some fallback that works at least for English

        if ($sortflag == core_collator::SORT_NUMERIC) {
            return asort($arr, SORT_NUMERIC);

        } else if ($sortflag == core_collator::SORT_REGULAR) {
            return asort($arr, SORT_REGULAR);
        }

        if (!$casesensitive) {
            $original = $arr;
            foreach ($arr as $key => $value) {
                $arr[$key] = core_text::strtolower($value);
            }
        }

        if ($sortflag == core_collator::SORT_NATURAL) {
            $result = natsort($arr);

        } else {
            $result = asort($arr, SORT_LOCALE_STRING);
        }

        if ($original) {
            self::restore_array($arr, $original);
        }

        return $result;
    }
public static function asort(array &$arr, $sortflag = core_collator::SORT_STRING) {
        if (empty($arr)) {
            // nothing to do
            return true;
        }

        $original = null;

        $casesensitive = (bool)($sortflag & core_collator::CASE_SENSITIVE);
        $sortflag = ($sortflag & ~core_collator::CASE_SENSITIVE);
        if ($sortflag != core_collator::SORT_NATURAL and $sortflag != core_collator::SORT_STRING) {
            $casesensitive = false;
        }

        if (self::ensure_collator_available()) {
            if ($sortflag == core_collator::SORT_NUMERIC) {
                $flag = Collator::SORT_NUMERIC;

            } else if ($sortflag == core_collator::SORT_REGULAR) {
                $flag = Collator::SORT_REGULAR;

            } else {
                $flag = Collator::SORT_STRING;
            }

            if ($sortflag == core_collator::SORT_NATURAL) {
                $original = $arr;
                if ($sortflag == core_collator::SORT_NATURAL) {
                    foreach ($arr as $key => $value) {
                        $arr[$key] = self::naturalise((string)$value);
                    }
                }
            }
            if ($casesensitive) {
                self::$collator->setAttribute(Collator::CASE_FIRST, Collator::UPPER_FIRST);
            } else {
                self::$collator->setAttribute(Collator::CASE_FIRST, Collator::OFF);
            }
            $result = self::$collator->asort($arr, $flag);
            if ($original) {
                self::restore_array($arr, $original);
            }
            return $result;
        }

        // try some fallback that works at least for English

        if ($sortflag == core_collator::SORT_NUMERIC) {
            return asort($arr, SORT_NUMERIC);

        } else if ($sortflag == core_collator::SORT_REGULAR) {
            return asort($arr, SORT_REGULAR);
        }

        if (!$casesensitive) {
            $original = $arr;
            foreach ($arr as $key => $value) {
                $arr[$key] = core_text::strtolower($value);
            }
        }

        if ($sortflag == core_collator::SORT_NATURAL) {
            $result = natsort($arr);

        } else {
            $result = asort($arr, SORT_LOCALE_STRING);
        }

        if ($original) {
            self::restore_array($arr, $original);
        }

        return $result;
    }
public static function asort ( array & $ arr , $ sortflag = core_collator :: SORT_STRING ) { if ( empty ( $ arr ) ) { // nothing to do return true ; } $ original = null ; $ casesensitive = ( bool ) ( $ sortflag & core_collator :: CASE_SENSITIVE ) ; $ sortflag = ( $ sortflag & ~ core_collator :: CASE_SENSITIVE ) ; if ( $ sortflag != core_collator :: SORT_NATURAL and $ sortflag != core_collator :: SORT_STRING ) { $ casesensitive = false ; } if ( self :: ensure_collator_available ( ) ) { if ( $ sortflag == core_collator :: SORT_NUMERIC ) { $ flag = Collator :: SORT_NUMERIC ; } else if ( $ sortflag == core_collator :: SORT_REGULAR ) { $ flag = Collator :: SORT_REGULAR ; } else { $ flag = Collator :: SORT_STRING ; } if ( $ sortflag == core_collator :: SORT_NATURAL ) { $ original = $ arr ; if ( $ sortflag == core_collator :: SORT_NATURAL ) { foreach ( $ arr as $ key => $ value ) { $ arr [ $ key ] = self :: naturalise ( ( string ) $ value ) ; } } } if ( $ casesensitive ) { self :: $ collator -> setAttribute ( Collator :: CASE_FIRST , Collator :: UPPER_FIRST ) ; } else { self :: $ collator -> setAttribute ( Collator :: CASE_FIRST , Collator :: OFF ) ; } $ result = self :: $ collator -> asort ( $ arr , $ flag ) ; if ( $ original ) { self :: restore_array ( $ arr , $ original ) ; } return $ result ; } // try some fallback that works at least for English if ( $ sortflag == core_collator :: SORT_NUMERIC ) { return asort ( $ arr , SORT_NUMERIC ) ; } else if ( $ sortflag == core_collator :: SORT_REGULAR ) { return asort ( $ arr , SORT_REGULAR ) ; } if ( ! $ casesensitive ) { $ original = $ arr ; foreach ( $ arr as $ key => $ value ) { $ arr [ $ key ] = core_text :: strtolower ( $ value ) ; } } if ( $ sortflag == core_collator :: SORT_NATURAL ) { $ result = natsort ( $ arr ) ; } else { $ result = asort ( $ arr , SORT_LOCALE_STRING ) ; } if ( $ original ) { self :: restore_array ( $ arr , $ original ) ; } return $ result ; }
Locale aware sorting, the key associations are kept, values are sorted alphabetically.

@param array $arr array to be sorted (reference)
@param int $sortflag One of core_collator::SORT_NUMERIC, core_collator::SORT_STRING, core_collator::SORT_NATURAL, core_collator::SORT_REGULAR
optionally "|" core_collator::CASE_SENSITIVE
@return bool True on success
Locale aware sorting the key associations are kept values are sorted alphabetically .