<?php
//Собственно, задача, дан массив чисел, найдите 2 наибольших. Решать можно на JS или PHP, кому что роднее.
$numbers = array(1, 500, 500, 500, 500, 2, 3, 4, 5, 22, 12, 12, 123, 52, 24);
function top2numbers
(array $numbers) {
$top1 = -INF;
$top2 = 0;
foreach ($numbers as $number) {
if ($number > $top1) {
$top2 = $top1;
$top1 = $number;
} elseif (($number > $top2) && ($number != $top1)) {
$top2 = $number;
}
}
return array($top1, $top2); }
PD9waHAKLy/QodC+0LHRgdGC0LLQtdC90L3Qviwg0LfQsNC00LDRh9CwLCDQtNCw0L0g0LzQsNGB0YHQuNCyINGH0LjRgdC10LssINC90LDQudC00LjRgtC1IDIg0L3QsNC40LHQvtC70YzRiNC40YUuINCg0LXRiNCw0YLRjCDQvNC+0LbQvdC+INC90LAgSlMg0LjQu9C4IFBIUCwg0LrQvtC80YMg0YfRgtC+INGA0L7QtNC90LXQtS4KCiRudW1iZXJzID0gYXJyYXkoMSwgNTAwLCA1MDAsIDUwMCwgNTAwLCAyLCAzLCA0LCA1LCAyMiwgMTIsIDEyLCAxMjMsIDUyLCAyNCk7CgpmdW5jdGlvbiB0b3AybnVtYmVycyAoYXJyYXkgJG51bWJlcnMpCnsKICAgICR0b3AxID0gLUlORjsKICAgICR0b3AyID0gMDsKICAgIGZvcmVhY2ggKCRudW1iZXJzIGFzICRudW1iZXIpIHsKICAgICAgICBpZiAoJG51bWJlciA+ICR0b3AxKSB7CiAgICAgICAgICAgICR0b3AyID0gJHRvcDE7CiAgICAgICAgICAgICR0b3AxID0gJG51bWJlcjsKICAgICAgICB9IGVsc2VpZiAoKCRudW1iZXIgPiAkdG9wMikgJiYgKCRudW1iZXIgIT0gJHRvcDEpKSB7CiAgICAgICAgICAgICR0b3AyID0gJG51bWJlcjsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gYXJyYXkoJHRvcDEsICR0b3AyKTsKfQoKCnByaW50X3IodG9wMm51bWJlcnMoJG51bWJlcnMpKTs=