1. Computing & Technology

Discuss in my forum

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
 ?>

©2012 About.com. All rights reserved.

A part of The New York Times Company.