Skip to content

Instantly share code, notes, and snippets.

@gbasov
Created September 29, 2012 15:23
Show Gist options
  • Save gbasov/3804346 to your computer and use it in GitHub Desktop.
Save gbasov/3804346 to your computer and use it in GitHub Desktop.
Word form
function word_form($value, $one_form, $two_form, $five_form){
$form = null;
$han_value = $value%100;
$ten_value = $value%10;
// x05 - x20, x0, x5 - x9,
if( ($han_value >= 5 && $han_value <= 20) || in_array( $ten_value, array(0, 5, 6, 7, 8, 9) ) ){
$form = $five_form;
// x2, x3, x4
} else if( in_array( $ten_value, array(2, 3, 4) ) ){
$form = $two_form;
// 1
} else {
$form = $one_form;
}
return $form;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment