PHP min()

Pitboz's avatar
Published Jun 7, 2023
Contribute to Docs

The min() function returns the lowest value out of a group or array of values.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours

Syntax

// Find the minimum value of a group of values
$lowest = min($value1, $value2, $value3, ...);

// Find the minimum value of an array of values
$values = array($n1, $n2, $n3, ...);
$lowest = min($values);
  • The values can be of any type. The min() function will use the standard comparison rules, so if a string value is compared to an integer, the string value is considered 0.
  • If multiple string values are added, then they will be compared alphanumerically. The returned value will not be converted and if two values are identical, the first in the order will be returned.
  • If the parameter is an array, the lowest value of the array will be returned.

Codebyte Examples

Code
Output

All contributors

Contribute to Docs

Learn PHP on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours