Skip to content

Instantly share code, notes, and snippets.

@d1i1m1o1n
Last active March 11, 2016 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d1i1m1o1n/2fcdf8fa061fbed53ac3 to your computer and use it in GitHub Desktop.
Save d1i1m1o1n/2fcdf8fa061fbed53ac3 to your computer and use it in GitHub Desktop.
Plural froms сколнения
<?php
function plural_form($n, $forms) {
return $n%10==1&&$n%100!=11?$forms[0]:($n%10>=2&&$n%10<=4&&($n%100<10||$n%100>=20)?$forms[1]:$forms[2]);
}
//usage
$ends = [
"банан",
"банана",
"бананов"
];
plural_form(1, $ends); //банан
plural_form(2, $ends); //банана
plural_form(5, $ends); //бананов
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment