max

Find the maximum number or alphabetically last string in an array

Definition

number|string max(array[number]|array[string] $collection)

Returns the highest found number in a number array, or the alphabetically last string in a string array.

Parameters

array[number] array[string] $collection

Array to find the maximum of. All entries must be numbers, or they must all be strings.

Returns

number | string

The largest number or the alphabetically last string in $collection.

Examples

{
    a: max(`[1, 2]`),
    b: max(`['alpha', 'beta']`),
    c: max(`['alpha', 3, 'beta']`),      // Error
    d: max(`['alpha', '4', 'beta']`),
    e: max(`[5.0, false, 6.0]`),
    f: max(`[null, -7, -8]`),
    g: max(`['alpha', 'beta', null]`),
    h: max(`['alpha', 'beta', true]`)    // Error
}
{
  "a": 2,
  "b": "beta",
  "d": "beta",
  "e": 6.0,      // false evaluates to 0
  "f": null,     // null evaluates to 0, valid
  "g": "beta"
}