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

Max () PHP Function

By , About.com Guide

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)
?>
Explore PHP / MySQL
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. 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 Max - Max PHP Function - Highest Number PHP

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

All rights reserved.