How to find max value from a nested array in php?


function MaxArray($arr)
{
   foreach($arr as $key => $val)
   {
      if ( is_array($val) ) $arr[$key] = MaxArray( $val );
   }

   sort($arr);

   return array_pop($arr);
}
$arr = array(
    array(141,151,161),
    2,
    3,
    array(
        101,
        202,
        array(303,404)
    )
);
MaxArray($arr);

Advertisements

One thought on “How to find max value from a nested array in php?

  1. I think that is among the such a lot significant information for me. And i am glad studying your article. But want to remark on few general issues, The site style is ideal, the articles is actually great : D. Excellent process, cheers

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s