Skip to content

Instantly share code, notes, and snippets.

@ArtemioVegas
Last active September 9, 2017 10:27
Show Gist options
  • Save ArtemioVegas/863e61bcf7cb478a8d21ddda259ca367 to your computer and use it in GitHub Desktop.
Save ArtemioVegas/863e61bcf7cb478a8d21ddda259ca367 to your computer and use it in GitHub Desktop.
Найти максимальное значение в многоуровневом массиве
<?php
/**
* Найти максимальное значение в многоуровневом массиве
* На входе array(1,2,array(400,12,13),3,4,array(21,22,23,array(231),),)
* На выходе 400
*/
function array_max($array)
{
static $max;
foreach($array as $sub)
{
if( ! is_array($sub))
{
$max = ($max >= $sub) ? $max : $sub;
}
else
{
array_max($sub);
}
}
return $max;
}
var_dump(array_max(array(1,2,array(400,12,13),3,4,array(21,22,23,array(231),),)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment