function ut_coll_asort($coll, &$arr, $sort_flag = Collator::SORT_REGULAR) { return $GLOBALS['oo-mode'] ? $coll->asort($arr, $sort_flag) : collator_asort($coll, $arr, $sort_flag); }
/** * Sorts an array with maintaining index association, elements will be arranged from the lowest to the highest. * @param array $array The input array. * @param int $sort_flag (optional) Shows how elements of the array to be compared. * @param string $language (optional) The language in which comparison is to be made. If language is omitted, interface language is assumed then. * @param string $encoding (optional) The used internally by this function character encoding. If it is omitted, the platform character set will be used by default. * @return bool Returns TRUE on success, FALSE on error. * Note: $sort_flag may have the following values: * SORT_REGULAR - internal PHP-rules for comparison will be applied, without preliminary changing types; * SORT_NUMERIC - items will be compared as numbers; * SORT_STRING - items will be compared as strings. If intl extension is enabled, then comparison will be language-sensitive using internally a created ICU locale; * SORT_LOCALE_STRING - items will be compared as strings depending on the current POSIX locale. If intl extension is enabled, then comparison will be language-sensitive using internally a created ICU locale. * This function is aimed at replacing the function asort() for sorting human-language strings. * @link http://php.net/manual/en/function.asort.php * @link http://php.net/manual/en/collator.asort.php */ function api_asort(&$array, $sort_flag = SORT_REGULAR, $language = null, $encoding = null) { if (INTL_INSTALLED) { if (empty($encoding)) { $encoding = _api_mb_internal_encoding(); } $collator = _api_get_collator($language); if (is_object($collator)) { if (api_is_utf8($encoding)) { $sort_flag = $sort_flag == SORT_LOCALE_STRING ? SORT_STRING : $sort_flag; return collator_asort($collator, $array, _api_get_collator_sort_flag($sort_flag)); } elseif ($sort_flag == SORT_STRING || $sort_flag == SORT_LOCALE_STRING) { global $_api_collator, $_api_encoding; $_api_collator = $collator; $_api_encoding = $encoding; return uasort($array, '_api_cmp'); } } } return asort($array, $sort_flag); }
/** * Locale aware sorting, the key associations are kept, values are sorted alphabetically. * @param array $arr array to be sorted * @param string $lang moodle language * @return void, modifies parameter */ function asort(array &$arr) { if (function_exists('collator_asort')) { $coll = collator_create(get_string('locale', 'langconfig')); collator_asort($coll, $arr); } else { asort($arr, SORT_LOCALE_STRING); } }