Wer eine römische Zahl ausgeben möchte, kann diese mit folgender Funktion ermitteln:
/**
* Gibt die römische Zahl einer arabischen Zahl zurück
*/
function getRoemischeZahl($arabische_zahl)
{
$ar_number = array(1000, 900, 500, 400,100, 90, 50, 40, 10, 9, 5, 4, 1);
$ar_char = array('M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I');
$roemische_zahl = '';
for ($count = 0; $count < count($ar_number); $count++)
{
while ($arabische_zahl >= $ar_number[$count]) {
$roemische_zahl .= $ar_char[$count];
$arabische_zahl -= $ar_number[$count];
}
}
return $roemische_zahl;
} // function getRoemischeZahl($arabische_zahl)
Die Anwendung erfolgt dann einfach mittels:
echo getRoemischeZahl(100);