Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

(no description)

File Size: 342 lines (12 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: Sort  - X-Ref

sort($sortArray, $sortIndex = 1, $sortOrder = self::ORDER_ASCENDING, $byColumn = false)   X-Ref
SORT
The SORT function returns a sorted array of the elements in an array.
The returned array is the same shape as the provided array argument.
Both $sortIndex and $sortOrder can be arrays, to provide multi-level sorting.

param: mixed $sortArray The range of cells being sorted
param: mixed $sortIndex The column or row number within the sortArray to sort on
param: mixed $sortOrder Flag indicating whether to sort ascending or descending
param: mixed $byColumn Whether the sort should be determined by row (the default) or by column
return: mixed The sorted values from the sort range

sortBy($sortArray, ...$args)   X-Ref
SORTBY
The SORTBY function sorts the contents of a range or array based on the values in a corresponding range or array.
The returned array is the same shape as the provided array argument.
Both $sortIndex and $sortOrder can be arrays, to provide multi-level sorting.

param: mixed $sortArray The range of cells being sorted
param: mixed $args
return: mixed The sorted values from the sort range

enumerateArrayKeys(array $sortArray)   X-Ref
No description

validateScalarArgumentsForSort(&$sortIndex, &$sortOrder, int $sortArraySize)   X-Ref
No description

validateSortVector($sortVector, int $sortArraySize)   X-Ref

param: mixed $sortVector

validateSortOrder($sortOrder)   X-Ref

param: mixed $sortOrder

validateArrayArgumentsForSort(&$sortIndex, &$sortOrder, int $sortArraySize)   X-Ref

param: array $sortIndex
param: mixed $sortOrder

prepareSortVectorValues(array $sortVector)   X-Ref
No description

processSortBy(array $sortArray, array $sortIndex, $sortOrder)   X-Ref
No description

sortByRow(array $sortArray, array $sortIndex, array $sortOrder)   X-Ref

param: int[] $sortIndex
param: int[] $sortOrder

sortByColumn(array $sortArray, array $sortIndex, array $sortOrder)   X-Ref

param: int[] $sortIndex
param: int[] $sortOrder

buildVectorForSort(array $sortArray, array $sortIndex, array $sortOrder)   X-Ref

param: int[] $sortIndex
param: int[] $sortOrder

executeVectorSortQuery(array $sortData, array $sortArguments)   X-Ref
No description

sortLookupArrayFromVector(array $sortArray, array $sortVector)   X-Ref
No description

applyPHP7Patch(array $sortArray, array $sortArguments)   X-Ref
Hack to handle PHP 7:
From PHP 8.0.0, If two members compare as equal in a sort, they retain their original order;
but prior to PHP 8.0.0, their relative order in the sorted array was undefined.
MS Excel replicates the PHP 8.0.0 behaviour, retaining the original order of matching elements.
To replicate that behaviour with PHP 7, we add an extra sort based on the row index.