min
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
{
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
}
{
"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
}
Updated 7 months ago