daily pastebin goal
10%
SHARE
TWEET

Untitled

a guest Jun 17th, 2012 283 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Variant of the numeral
  3.  *
  4.  * @param array         word in three variant (1, 2, 5)
  5.  *
  6.  * @return string       string for current numeral
  7.  *
  8.  * @example             variantNumeral(array('materiał', 'materiały', 'materiałów'), 5) => 5 materiałów
  9. **/
  10. function variantNumeral(array $words, $num) {
  11.         $num_m1 = $num % 100;
  12.        
  13.         if ($num_m1 == 1 && $num < 100) {
  14.                 $word = $words[0];
  15.         } else {
  16.                 $num_m2 = $num_m1 % 10;
  17.                
  18.                 if (($num_m2 > 1 && $num_m2 < 5) && ($num_m1 < 12 || $num_m1 > 14)) {
  19.                         $word = $words[1];
  20.                 } else {
  21.                         $word = $words[2];
  22.                 }
  23.         }
  24.                
  25.         return $num . ' ' . $word;
  26. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand