Sort
extends LookupRefValidations
in package
Table of Contents
Constants
- ORDER_ASCENDING = 1
- ORDER_DESCENDING = -1
Methods
- sort() : mixed
- SORT The SORT function returns a sorted array of the elements in an array.
- sortBy() : mixed
- SORTBY The SORTBY function sorts the contents of a range or array based on the values in a corresponding range or array.
- validateInt() : int
- validatePositiveInt() : int
Constants
ORDER_ASCENDING
public
mixed
ORDER_ASCENDING
= 1
ORDER_DESCENDING
public
mixed
ORDER_DESCENDING
= -1
Methods
sort()
SORT The SORT function returns a sorted array of the elements in an array.
public
static sort(mixed $sortArray[, mixed $sortIndex = 1 ][, mixed $sortOrder = self::ORDER_ASCENDING ][, mixed $byColumn = false ]) : mixed
The returned array is the same shape as the provided array argument. Both $sortIndex and $sortOrder can be arrays, to provide multi-level sorting.
NOTE: If $sortArray contains a mixture of data types (string/int/bool), the results may be unexpected. This is also true if the array consists of string representations of numbers, especially if there are both positive and negative numbers in the mix.
Parameters
- $sortArray : mixed
-
The range of cells being sorted
- $sortIndex : mixed = 1
-
The column or row number within the sortArray to sort on
- $sortOrder : mixed = self::ORDER_ASCENDING
-
Flag indicating whether to sort ascending or descending Ascending = 1 (self::ORDER_ASCENDING) Descending = -1 (self::ORDER_DESCENDING)
- $byColumn : mixed = false
-
Whether the sort should be determined by row (the default) or by column
Return values
mixed —The sorted values from the sort range
sortBy()
SORTBY The SORTBY function sorts the contents of a range or array based on the values in a corresponding range or array.
public
static sortBy(mixed $sortArray, mixed ...$args) : mixed
The returned array is the same shape as the provided array argument. Both $sortIndex and $sortOrder can be arrays, to provide multi-level sorting. Microsoft doesn't even bother documenting that a column sort is possible. However, it is. According to: https://exceljet.net/functions/sortby-function When by_array is a horizontal range, SORTBY sorts horizontally by columns. My interpretation of this is that by_array must be an array which contains exactly one row.
NOTE: If the "byArray" contains a mixture of data types (string/int/bool), the results may be unexpected. This is also true if the array consists of string representations of numbers, especially if there are both positive and negative numbers in the mix.
Parameters
- $sortArray : mixed
-
The range of cells being sorted
- $args : mixed
-
At least one additional argument must be provided, The vector or range to sort on After that, arguments are passed as pairs: sort order: ascending or descending Ascending = 1 (self::ORDER_ASCENDING) Descending = -1 (self::ORDER_DESCENDING) additional arrays or ranges for multi-level sorting
Return values
mixed —The sorted values from the sort range
validateInt()
public
static validateInt(mixed $value) : int
Parameters
- $value : mixed
Return values
intvalidatePositiveInt()
public
static validatePositiveInt(mixed $value[, bool $allowZero = true ]) : int
Parameters
- $value : mixed
- $allowZero : bool = true