Skip to content

Instantly share code, notes, and snippets.

@YuriDan
Created October 21, 2013 10:35
Show Gist options
  • Save YuriDan/7081794 to your computer and use it in GitHub Desktop.
Save YuriDan/7081794 to your computer and use it in GitHub Desktop.
<? // $int - число, $expressions - массив н.р. $expressions = Array("0"=>"программа", "1"=>"программы", "2"=>"программ");
function sklon($int, $expressions)
{
if (count($expressions) < 3) $expressions[2] = $expressions[1];
settype($int, "integer");
$count = $int % 100;
if ($count >= 5 && $count <= 20) {
$result = $expressions['2'];
} else {
$count = $count % 10;
if ($count == 1) {
$result = $expressions['0'];
} elseif ($count >= 2 && $count <= 4) {
$result = $expressions['1'];
} else {
$result = $expressions['2'];
}
}
return $result;
}?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment