Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.71 KB | None | 0 0
  1. <?php
  2. global $max;
  3. $max = null;
  4.  
  5. function checkAndSetMaxEl($digit) {
  6.     global $max;
  7.    
  8.     if ($digit > $max) {
  9.         $max = $digit;
  10.     }  
  11. }
  12.  
  13. function checkArrayHelper($el) {
  14.     foreach ($el as $subEl) {
  15.         if (!is_array($subEl)) {
  16.             checkAndSetMaxEl($subEl);
  17.             continue;
  18.         }
  19.        
  20.         checkArrayHelper($subEl);
  21.     }
  22. }
  23.  
  24. function intMax($arr) {
  25.     global $max;
  26.    
  27.     foreach ($arr as $el) {
  28.         if (!is_array($el)) {
  29.             checkAndSetMaxEl($el);
  30.             continue;
  31.         }
  32.        
  33.         checkArrayHelper($el);
  34.     }
  35.    
  36.     return $max;
  37. }
  38.  
  39. echo intMax([1, [2, 3], [2, [1, [5], [1, [], [[]], [4, 9]]], 4], 2]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement