The NumberFormatter class can be used to convert integer numbers to Roman numerals without a custom function using an array of symbols and associated values:
<?php
function intToRomanNumeral(int $num) {
static $nf = new NumberFormatter('@numbers=roman', NumberFormatter::DECIMAL);
return $nf->format($num);
}
echo intToRomanNumeral(2); // II
echo intToRomanNumeral(5); // V
echo intToRomanNumeral(10); // X
echo intToRomanNumeral(50); // L
echo intToRomanNumeral(57); // LVII
echo intToRomanNumeral(58); // LVIII
echo intToRomanNumeral(100); // C
echo intToRomanNumeral(150); // CL
echo intToRomanNumeral(1000); // M
echo intToRomanNumeral(10000); // ↂ
?>