PHP min() Function: Finding the Minimum Value
This article explains how PHP's min() function determines the smallest value, detailing its behavior with single array arguments versus multiple scalar arguments, describing parameters and return values, and providing clear code examples for common use cases.
The min() function in PHP returns the smallest value among its arguments. When a single array is passed, it returns the minimum element of that array; with multiple arguments, it compares them and returns the smallest.
Parameters mixed $values – an array of values, or multiple comparable values ( $value1, $value2, ...).
Return value
Returns the lowest value among the provided arguments. If arrays are compared, they are considered larger than scalar values.
Examples
<?php
echo min(2,3,1,6,7); // 1
echo min(array(2,4,5)); // 2
echo min(0, 'hello'); // 0
echo min('hello', -1); // -1
$val = min(array(2,4,8), array(2,5,1));
?>When mixing arrays and scalars, arrays are treated as larger, so the function returns the scalar minimum.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
