Last active
September 9, 2017 10:27
-
-
Save ArtemioVegas/863e61bcf7cb478a8d21ddda259ca367 to your computer and use it in GitHub Desktop.
Найти максимальное значение в многоуровневом массиве
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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