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.

Updated on: 2026-03-15T07:29:07+05:30

177 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements