PHP min() Function
In this chapter you will learn:
- Definition for PHP min() Function
- Syntax for PHP min() Function
- Parameter for PHP min() Function
- Return for PHP min() Function
- Example - Find lowest value with the min() function
- Example - Finding the Greatest and Least Values in a key-value pair
Definition
The min()
function returns the lowest value in an array,
or the lowest value of several values.
Syntax
PHP min() Function has the following syntax.
min(array_values);
or
min(value1,value2,...);
Parameter
Parameter | Is Required | Description |
---|---|---|
array_values | Required. | Array containing the values |
value1,value2,... | Required. | Values to compare (must be at least two values) |
Return
Item | Description |
---|---|
Return Value | The numerically lowest value |
Return Type | Mixed |
Example 1
Find lowest value with the min()
function:
<?php
echo(min(2,4,6,8,10) . "<br>");
echo(min(array(4,6,8,10)) . "<br>");
?>
The code above generates the following result.
Example 2
Finding the Greatest and Least Values in a key-value pair
<?php/*from j a v a 2s. c o m*/
$langs = array( 'PHP' => 1, 'Java' => 2, 'Java2s.com' => 3,);
printf("<p>Most items: %d; least items: %d.</p>\n",
max($langs), min($langs));
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP mt_getrandmax() Function
- Syntax for PHP mt_getrandmax() Function
- Parameter for PHP mt_getrandmax() Function
- Return for PHP mt_getrandmax() Function
- Example - Return largest possible random value that can be returned by mt_rand()
Home » PHP Tutorial » PHP Math Functions