Advertisement
Guest User

Function to return highest value in an array

a guest
May 20th, 2013
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.32 KB | None | 0 0
  1. function MaxArray($arr){
  2.     $maxValue = 0;
  3.     foreach($arr as $element)
  4.     {  
  5.         if(count($element)>1)
  6.         {
  7.             $tempMax = MaxArray($element);
  8.             if($tempMax > $maxValue)
  9.             {
  10.                 $maxValue = $tempMax;
  11.             }
  12.         }else{
  13.            
  14.             if($element > $maxValue)
  15.             {
  16.                 $maxValue = $element;
  17.             }
  18.         }
  19.     }
  20.     return $maxValue;  
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement