min

Modified on Thu, 9 Jul at 10:49 AM

min

TABLE OF CONTENTS

Find the minimal number or alphabetically first string in an array

Definition

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

Returns the lowest found number in a number array, or the alphabetically first string in a string array.

Parameters

array[number] array[string] $collection

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

Returns

number | string

The lowest number or the alphabetically first string in $collection.

Examples

Transformation
{
    a: min(`[1, 2]`),
    b: min(`['alpha', 'beta']`),
    c: min(`['alpha', 3, 'beta']`),       // Error
    d: min(`['alpha', '4', 'beta']`),
    e: min(`[5, false, 6]`),
    f: min(`[null, -7.0, -8.0]`),
    g: min(`['alpha', 'beta', null]`),
    h: min(`['alpha', 'beta', true]`)     // Error
}
Result
{
  "a": 1,
  "b": "alpha",
  "d": "4",
  "e": false,    // false evaluates to 0
  "f": -8.0,     // null evaluates to 0, valid
  "g": null,     // null is smaller than all strings, valid
}

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