max

Modified on Thu, 9 Jul at 10:49 AM

max

TABLE OF CONTENTS

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

Transformation
{
    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
}
Result
{
  "a": 2,
  "b": "beta",
  "d": "beta",
  "e": 6.0,      // false evaluates to 0
  "f": null,     // null evaluates to 0, valid
  "g": "beta"
}

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article