Условия IF и ELSE - помогите пожалуйста

12
iNd
На сайте с 20.03.2009
Offline
122
iNd
#11

эх, горе-программисты...

Saacy
На сайте с 20.10.2008
Offline
78
#12

<?php

function getPeriodString($num,$base,$endings) {
if ($num % 100 >= 11 && $num % 100 <= 19) {
return $base.$endings[2];
} else {
switch ($num % 10) {
case 1:
return $base.$endings[0];
case 2: case 3: case 4:
return $base.$endings[1];
default:
return $base.$endings[2];
}
}
}
function timeLeft($f) {
$time = $f - time();
if ($time <= 0)
return 0;
if ($time > 604800) {
$base = 'недел';
$endings = array('я','и','ь');
$left = floor($time/604800);
} elseif ($time > 86400) {
$base = 'д';
$endings = array('ень','ня','ней');
$left = floor($time/86400);
} elseif ($time > 3600) {
$base = 'час';
$endings = array('','а','ов');
$left = floor($time/3600);
} elseif ($time > 60) {
$base = 'минут';
$endings = array('а','ы','');
$left = floor($time/60);
}
return $left." ".getPeriodString($left,$base,$endings);
}

$timestamp = strtotime("31.12.2009 23:59:59"); // метка окончания = 1262293199
echo timeLeft($timestamp); // если время наступило, вернёт 0
?>

Комментарии платно)

Ищу доноров RU/EN/FR/DE/ES/PT (/ru/forum/888035)
12

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий