fork download
  1. <?php
  2.  
  3. function twoMax(Array $arr) {
  4. if (count($arr) < 2 ) return $arr;
  5. foreach ($arr as $key => $value) {
  6. if ( !isset($second) ) {
  7. $second = $value;
  8. continue;
  9. }
  10. if ( !isset($first) && $value > $second) {
  11. $second = $value;
  12. continue;
  13. }
  14. if (isset($first) && ( ($value > $second) && ($value < $first) ) ) {
  15. $second = $value;
  16. continue;
  17. }
  18. if ( (!isset($first) && ($value > $second) ) || ($value > $first) ) {
  19. $first = $value;
  20. }
  21. }
  22. $result = (isset($first) ) ? [$first, $second] : [$second];
  23. return $result;
  24. }
Success #stdin #stdout 0.01s 24448KB
stdin
Standard input is empty
stdout
Standard output is empty