Skip to content

Instantly share code, notes, and snippets.

@dmacompton
Created March 30, 2015 09:56
Show Gist options
  • Save dmacompton/d0c584fbdb99881919f5 to your computer and use it in GitHub Desktop.
Save dmacompton/d0c584fbdb99881919f5 to your computer and use it in GitHub Desktop.
Склонение php
function sklonen($n,$s1,$s2,$s3, $b = false){
$m = $n % 10; $j = $n % 100;
if($b) $n = '<b>'.$n.'</b>';
if($m==0 || $m>=5 || ($j>=10 && $j<=20)) return $n.' '.$s3;
if($m>=2 && $m<=4) return $n.' '.$s2;
return $n.' '.$s1;
}
var_dump(sklonen(10, 'комната', 'комнаты', 'комнат'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment