You want to find the largest or smallest valued element in an array.
Use max() to find the largest element, and min() to find the smallest.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN"> <head> <title>PHP</title> <meta Name="Author" Content="Hann So"> </head> <body> <p> <?php $fruits = array('Apples', 'Grapes', 'Bananas', 'Oranges'); print_r($fruits); $largest = max($fruits); echo "<p>The largest value is $largest.</p>"; $fruits = array('red'=>'Apples', 'green'=>'Grapes', 'yellow'=>'Bananas', 'orange'=>'Oranges'); print_r($fruits); $smallest = min($fruits); echo "<p>The smallest value is $smallest.</p>"; ?> </p> </body> </html> |