<?php
function twoMax
(Array $arr) { if (count($arr) < 2 ) return $arr; foreach ($arr as $key => $value) {
$second = $value;
continue;
}
if ( !isset($first) && $value > $second) { $second = $value;
continue;
}
if (isset($first) && ( ($value > $second) && ($value < $first) ) ) { $second = $value;
continue;
}
if ( (!isset($first) && ($value > $second) ) || ($value > $first) ) { $first = $value;
}
}
$result = (isset($first) ) ?
[$first, $second] : [$second]; return $result;
}
PD9waHAKCmZ1bmN0aW9uIHR3b01heChBcnJheSAkYXJyKSB7CglpZiAoY291bnQoJGFycikgPCAyICkgcmV0dXJuICRhcnI7Cglmb3JlYWNoICgkYXJyIGFzICRrZXkgPT4gJHZhbHVlKSB7CgkJaWYgKCAgIWlzc2V0KCRzZWNvbmQpICApIHsKCQkJJHNlY29uZCA9ICR2YWx1ZTsKCQkJY29udGludWU7CgkJfQoJCWlmICggIWlzc2V0KCRmaXJzdCkgJiYgJHZhbHVlID4gJHNlY29uZCkgewoJCQkkc2Vjb25kID0gJHZhbHVlOwoJCQljb250aW51ZTsKCQl9CgkJaWYgKGlzc2V0KCRmaXJzdCkgJiYgKCAoJHZhbHVlID4gJHNlY29uZCkgJiYgKCR2YWx1ZSA8ICRmaXJzdCkgKSApIHsKCQkJJHNlY29uZCA9ICR2YWx1ZTsKCQkJY29udGludWU7CgkJfQoJCWlmICggKCFpc3NldCgkZmlyc3QpICYmICgkdmFsdWUgPiAkc2Vjb25kKSApIHx8ICgkdmFsdWUgPiAkZmlyc3QpICkgewoJCQkkZmlyc3QgPSAkdmFsdWU7CgkJfQoJfQoJJHJlc3VsdCA9IChpc3NldCgkZmlyc3QpICkgID8gIFskZmlyc3QsICRzZWNvbmRdIDogWyRzZWNvbmRdOwoJcmV0dXJuICRyZXN1bHQ7Cn0=