Last active
October 9, 2018 19:52
-
-
Save Anduin-/e02166f8649c7f384ef5aced92983e49 to your computer and use it in GitHub Desktop.
Plural
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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