<?php
namespace Filters;
use Nette;
class inflectionConvertor
{
use Nette\SmartObject;
public function __invoke($num, $array)
{
return $this->create($num, $array);
}
/**
*
* @param int|float $number number how much of items there are
* @param array|string $array array or structured string of data for inflection
*
* @return false|mixed|string
*/
public function create(int|float $number, array|string $array): mixed
{
if (is_array($array)) {
$tmpArr = $array;
} else {
$infArr = preg_split('/\\r\\n|\\r|\\n/', $array);
$tmpArr = [];
foreach ($infArr as $item) {
$tmp = explode(':', $item);
$tmpArr[(int) $tmp[0]] = $tmp[1];
}
}
krsort($tmpArr);
foreach ($tmpArr as $id => $value) {
if ($number >= $id) {
return $value;
}
}
ksort($tmpArr);
return reset($tmpArr);
}
}