Definition and Usage
The min () function returns lowest element in array, or lowest amongst two or more comma separated parameters.
Syntax
min ( array $values ) : mixed
Or
min ( mixed $value1 [, mixed $... ] ) : mixed
Parameters
Sr.No | Parameter & Description |
---|---|
1 | values If only one parameter is given, it should be an array of valaues which may be of same or different types |
2 | value1, value2, .. If two or more parameters aregiven, they should be any comparable values of same or different types |
Return Values
PHP min() function returns lowest value from the array parameter or sequence of values. Standard comparison operators are applicable. If multiple values of different types evaluate as equal (e.g. 0 and 'PHP') the first parameter to the function will be returned.
PHP Version
This function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.
Example
Following example returns smallest value from numeric array.
<?php $arg=array(23, 5.55, 142, 56, 99); echo "array="; foreach ($arg as $i) echo $i . ","; echo "\n"; echo "min = " . min($arg); ?>
Output
This will produce following result −
array=23,5.55,142,56,99, min = 5.55
Example
Following example returns min() from array of strings.−
<?php $arg=array("Java", "Angular", "PHP", "C", "Kotlin"); echo "array="; foreach ($arg as $i) echo $i . ","; echo "\n"; echo "min = " . min($arg); ?>
Output
This will produce following result −
array=Java,Angular,PHP,C,Kotlin, min = Angular
Example
Series of string values are provided to min() function in following example;
<?php $val1="Java"; $val2="Angular"; $val3="PHP"; $val4="C"; $val5="Kotlin"; echo "values=" . $val1 . "," . $val2 . "," . $val3 . "," . $val4 . "," . $val5 . "\n"; echo "min = " . min($val1, $val2, $val3,$val4,$val5); ?>
Output
This will produce following result −
values=Java,Angular,PHP,C,Kotlin min = Angular
Example
In following example array is a collection of mixed data types −
<?php $arg=array(23, "Java", 142, 1e2, 99); echo "array="; foreach ($arg as $i) echo $i . ","; echo "\n"; echo "min = " . min($arg); ?>
Output
This will produce following result −
array=23,Java,142,100,99, min = Java