30 $numeral = array_shift($roman);
31 if (!isset(self::ROMAN_LOOKUP[$numeral])) {
32 throw new Exception(
'Invalid character detected');
35 $arabic = self::ROMAN_LOOKUP[$numeral];
36 if (count($roman) > 0 && isset(self::ROMAN_LOOKUP[$roman[0]]) && $arabic < self::ROMAN_LOOKUP[$roman[0]]) {
39 $sum += ($arabic - $subtract);
43 if (count($roman) > 0) {
44 self::calculateArabic($roman, $sum, $subtract);
55 return is_array($value) ? $value : [];
58 private static function strSplit(
string $roman): array
60 $rslt = str_split($roman);
62 return self::mollifyScrutinizer($rslt);
86 $negativeNumber = $roman[0] ===
'-';
87 if ($negativeNumber) {
88 $roman = substr($roman, 1);
92 $arabic = self::calculateArabic(self::strSplit($roman));
97 if ($negativeNumber) {
static evaluate($roman)
ARABIC.
static strSplit(string $roman)
const static calculateArabic(array $roman, &$sum=0, $subtract=0)
Recursively calculate the arabic value of a roman numeral.
static mollifyScrutinizer($value)
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.