min() returns the lowest value from the supplied arguments or from an array.
$temperatures = [28.4, 25.7, 31.2, 26.1];
echo min($temperatures); // 25.7
Use values of compatible types when possible. Mixing unrelated types can make comparisons harder to reason about.
echo min(4,8,2); // 2
echo "<br>";
echo min(5,-1,0); // -1
echo "<br>";
echo min(2,0,-3); //-3
echo "<br>";
echo min(array(4,6,1)); // 1
echo "<br>";
Syntax
min($value1, $value2, ...)
We can get the minimum value from two or more comparable values by using min().
<?Php
echo min(-5.8,5,44,-56); //Output is -56
?>
When all values are strings, min() compares them using PHP's normal string comparison rules. Avoid mixing strings and numbers in the same call because type juggling can make the result difficult to interpret.
$smallest = min('apple', 'banana', 'cherry');
echo $smallest; // apple
<?Php
echo min(array(-6,8,-22,3,15,-5)); //Output is -22
?>
$min_value = min(3, 9, 2, 5, 10);
echo $min_value; // Output: 2
$numbers = [12, 45, 3, 9, 27];
echo min($numbers); // Output: 3
$result = min("apple", "banana", "cherry");
echo $result; // Output: apple (based on lexicographic order)
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.