Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.27 KB | None | 0 0
  1. <?php
  2.  
  3. function my_max($xs)
  4. {
  5.     $max = null;
  6.  
  7.     foreach ($xs as $x) {
  8.         if (is_array($x)) {
  9.             $x = my_max($x);
  10.         }
  11.  
  12.         if ($x > $max) {
  13.             $max = $x;
  14.         }
  15.     }
  16.  
  17.     return $max;
  18. }
  19.  
  20. echo my_max([1, [2, 3]]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement