roman.thumbnail

In many cases, we , php programmers need Roman number display I II III IV etc.

Here is a simple algorithm for that .

1000, 'CM' => 900, 'D' => 500, 'CD' => 400, 'C' => 100, 'XC' => 90, 'L' => 50, 'XL' => 40, 'X' => 10, 'IX' => 9, 'V' => 5, 'IV' => 4, 'I' => 1); foreach ($lookup as $roman => $value) { // Determine the number of matches $matches = intval($n / $value); // Store that many characters $result .= str_repeat($roman, $matches); // Substract that from the number $n = $n % $value; } // The Roman numeral should be built, return it return $result; } ?>