Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function my_max_internal_compare($x, $max)
- {
- return ($x > $max ? $x : $max);
- }
- function my_max_internal($x0, $max)
- {
- if (is_null($x0)) return $max;
- if (!is_array($x0)) return my_max_internal_compare($x0, $max);
- if (count($x0) < 1) return $max;
- foreach ($x0 as $x)
- {
- $max = my_max_internal($x, $max);
- }
- return $max;
- }
- function my_max($xs)
- {
- if (is_null($xs) || count($xs) < 1) return 0;
- $max = -2147483648; //PHP_INT_MIN
- foreach ($xs as $x0)
- {
- $max = my_max_internal($x0, $max);
- }
- return $max;
- }
- echo my_max([1, 2, [3, [1000, 4, 5], 6, 7], 8, 9]) . "\n"; // 1000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement