Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 403]

Defines string apis

Copyright: 2011 Sam Hemelryk
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 349 lines (15 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: core_collator  - X-Ref

A collator class with static methods that can be used for sorting.

__construct()   X-Ref
Prevent class instances, all methods are static.


ensure_collator_available()   X-Ref
Ensures that a collator is available and created

return: bool Returns true if collation is available and ready

restore_array(array &$arr, array &$original)   X-Ref
Restore array contents keeping new keys.

param: array $arr
param: array $original
return: void modifies $arr

naturalise($string)   X-Ref
Normalise numbers in strings for natural sorting comparisons.

param: string $string
return: string string with normalised numbers

callback_naturalise($matches)   X-Ref

param: array $matches
return: string

asort(array &$arr, $sortflag = core_collator::SORT_STRING)   X-Ref
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
return: bool True on success

asort_objects_by_property(array &$objects, $property, $sortflag = core_collator::SORT_STRING)   X-Ref
Locale aware sort of objects by a property in common to all objects

param: array $objects An array of objects to sort (handled by reference)
param: string $property The property to use for comparison
param: int $sortflag One of core_collator::SORT_NUMERIC, core_collator::SORT_STRING, core_collator::SORT_NATURAL, core_collator::SORT_REGULAR
return: bool True on success

asort_objects_by_method(array &$objects, $method, $sortflag = core_collator::SORT_STRING)   X-Ref
Locale aware sort of objects by a method in common to all objects

param: array $objects An array of objects to sort (handled by reference)
param: string $method The method to call to generate a value for comparison
param: int $sortflag One of core_collator::SORT_NUMERIC, core_collator::SORT_STRING, core_collator::SORT_NATURAL, core_collator::SORT_REGULAR
return: bool True on success

asort_array_of_arrays_by_key(array &$array, $key, $sortflag = core_collator::SORT_STRING)   X-Ref
Locale aware sort of array of arrays.

Given an array like:
$array = array(
array('name' => 'bravo'),
array('name' => 'charlie'),
array('name' => 'alpha')
);

If you call:
core_collator::asort_array_of_arrays_by_key($array, 'name')

You will be returned $array sorted by the name key of the subarrays. e.g.
$array = array(
array('name' => 'alpha'),
array('name' => 'bravo'),
array('name' => 'charlie')
);

param: array $array An array of objects to sort (handled by reference)
param: string $key The key to use for comparison
param: int $sortflag One of
return: bool True on success

ksort(array &$arr, $sortflag = core_collator::SORT_STRING)   X-Ref
Locale aware sorting, the key associations are kept, keys 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
return: bool True on success