Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- global $max;
- $max = null;
- function checkAndSetMaxEl($digit) {
- global $max;
- if ($digit > $max) {
- $max = $digit;
- }
- }
- function checkArrayHelper($el) {
- foreach ($el as $subEl) {
- if (!is_array($subEl)) {
- checkAndSetMaxEl($subEl);
- continue;
- }
- checkArrayHelper($subEl);
- }
- }
- function intMax($arr) {
- global $max;
- foreach ($arr as $el) {
- if (!is_array($el)) {
- checkAndSetMaxEl($el);
- continue;
- }
- checkArrayHelper($el);
- }
- return $max;
- }
- echo intMax([1, [2, 3], [2, [1, [5], [1, [], [[]], [4, 9]]], 4], 2]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement