Skip to content

Instantly share code, notes, and snippets.

@atma
Created May 16, 2011 04:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atma/973925 to your computer and use it in GitHub Desktop.
Save atma/973925 to your computer and use it in GitHub Desktop.
Russian (ukrainian) plural form
<?php
/**
* @param int The number of items
* @param array Three item forms as for 1, 2-4(22,33), 5(66,78) respectively
*/
function plural_form($n, $forms)
{
$n = abs($n) % 100;
$n1 = $n % 10;
if ($n > 10 AND $n < 20) return $forms[2];
if ($n1 > 1 AND $n1 < 5) return $forms[1];
if ($n1 == 1) return $forms[0];
return $forms[2];
}
// Example usage
plural_form(1, array("месяц", "месяца", "месяцев")); // месяц
plural_form(32, array("месяц", "месяца", "месяцев")); // месяца
plural_form(15, array("месяц", "месяца", "месяцев")); // месяцев
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment