1. Technology
Send to a Friend via Email
You can opt-out at any time. Please refer to our privacy policy for contact information.

Max () PHP Function

By

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

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

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

 echo max ('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, 9, 1)

 // If both an array and non-array are given, the array
 // is always returned as the largest
 $x = max('about', array(2, 4, 6), 99) ; 
 //Returns array (2, 4, 6)
 ?>
Related Video
Basic PHP Syntax
Using PHP With HTML
  1. About.com
  2. Technology
  3. PHP / MySQL
  4. PHP Functions
  5. Highest Number (Max) PHP Function

©2014 About.com. All rights reserved.