Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Russian Plural Form in PHP
<?php
/*
echo plural_form(42, array('арбуз', 'арбуза', 'арбузов'));
*/
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]);
}
@scherbakoff

This comment has been minimized.

Copy link

commented Jul 28, 2017

$n = abs(intval($n));

@MurzNN

This comment has been minimized.

Copy link

commented Oct 5, 2017

Will be good to add support for not-integer (float) numbers via this small change:

  return is_float($n)?$forms[1]:($n%10==1&&$n%100!=11?$forms[0]:($n%10>=2&&$n%10<=4&&($n%100<10||$n%100>=20)?$forms[1]:$forms[2]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.