Skip to content

Instantly share code, notes, and snippets.

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 ilyahoilik/d1da047dbc94d2f9ab627b3ddbded3ce to your computer and use it in GitHub Desktop.
Save ilyahoilik/d1da047dbc94d2f9ab627b3ddbded3ce to your computer and use it in GitHub Desktop.
Plural
<?php
function get_word_form( $count, $word_forms = [ 'предмет', 'предмета', 'предметов' ] ) {
$count = preg_replace( '/[^\d]/', '', $count );
$n100 = $count % 100;
$n10 = $count % 10;
if ( ( $n100 > 10 ) && ( $n100 < 20 ) ) {
return $word_forms[2];
} elseif ( $n10 == 1 ) {
return $word_forms[0];
} elseif ( ( $n10 >= 2 ) && ( $n10 <= 4 ) ) {
return $word_forms[1];
} else {
return $word_forms[2];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment