View difference between Paste ID: hgEDAaRG and niURaJWx
SHOW: | | - or go back to the newest paste.
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
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
}