diff --git a/functions/functions.php b/functions/functions.php index 96754d9..505d5ff 100644 --- a/functions/functions.php +++ b/functions/functions.php @@ -15,6 +15,9 @@ function array_fill_like_list(array &$target_array, array $indexes, array $sourc function array_search_callback(array $a, callable $callback); function array_sort_in_given_order(array $array, array $order, $sort_key):array; + function http_redirect($uri, $replace_prev_headers = false, $code = 302, $scheme = ''); + + function pluralForm($number, $forms, string $glue = '|'):string; } if (!function_exists('Arris\checkAllowedValue')) { @@ -254,6 +257,35 @@ function http_redirect($uri, $replace_prev_headers = false, $code = 302, $scheme } } +if (!function_exists('Arris\pluralForm')) { + /** + * + * @param $number + * @param array $forms (array or string with glues, x|y|z or [x,y,z] + * @param string $glue + * @return string + */ + function pluralForm($number, $forms, string $glue = '|'):string + { + if (is_string($forms)) { + $forms = explode($forms, $glue); + } elseif (!is_array($forms)) { + return ''; + } + + if (count($forms) != 3) return ''; + + return + ($number % 10 == 1 && $number % 100 != 11) + ? $forms[0] + : ( + ($number % 10 >= 2 && $number % 10 <= 4 && ($number % 100 < 10 || $number % 100 >= 20)) + ? $forms[1] + : $forms[2] + ); + } +} + // template function if (!function_exists('Arris\__template__')) { function __template__()