1. Home
  2. Computing & Technology
  3. PHP / MySQL

Min () PHP Function

By , About.com Guide

Definition: The min () function returns the lowest number in a group or array. Any strings are seen as having a value of 0, and in the case that 0 is the lowest number the first case will be returned. You can also compare multiple arrays. This compares each individual array element, and whichever has a lower number first, is returned as the min. If an array is compared to a non array, the array is always seen as being the largest, and therefor never returned as the min.
Also Known As: PHP Minimum
Examples:
<?php
echo min(2, 4, 6, 8) ;
// Returns 2

echo min (array(2, 14, 7)) ;
//Returns 2

echo min(0, 'about') ;
//Returns 0

echo min ('about', 0) ;
// Returns about

// Comparing two arrays
// so in our example: 5 = 5, but 7 < 9
$x = max(array(5, 7, 12), array(5, 9, 1)) ;
//Returns array(5, 7, 12)

// If both an array and non-array are given, the array is always seen as the largest, and therefor not returned
$x = max('about', array(2, 4, 6), 99) ;
//Returns about, as it is seen as 0
?>
Explore PHP / MySQL
About.com Special Features

The Best Web Trends of the Decade

A look back at the best innovations, ideas and technologies over the last 10 years, More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. PHP Functions
  5. PHP Min - Min PHP Function - Lowest Number PHP

©2009 About.com, a part of The New York Times Company.

All rights reserved.