Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
min() function in PHP
The min() function in PHP returns the minimum value from a given set of values or an array. It compares all provided values and returns the smallest one.
Syntax
min(arr_values); or min(val1, val2, ...);
Parameters
arr_values − An array containing the values to compare.
val1, val2, ... − Individual values to compare (can pass multiple arguments).
Return Value
Returns the minimum value from the provided arguments or array. The return type matches the type of the smallest value.
Example 1: Using Multiple Arguments
Finding the minimum value from multiple numeric arguments ?
<?php
echo min(70, 89, 12, 34, 23, 66, 34);
?>
12
Example 2: Using an Array
Finding the minimum value from an array ?
<?php
$numbers = array(70, 89, 12, 34, 23, 66, 34);
echo min($numbers);
?>
12
Example 3: Comparing Different Data Types
The function can also compare strings and mixed data types ?
<?php
echo min("apple", "banana", "cherry") . "<br>";
echo min(5, "10", 3.14);
?>
apple 3.14
Conclusion
The min() function is useful for finding the smallest value from multiple arguments or arrays. It works with numbers, strings, and mixed data types, making it versatile for various comparison needs.
