Current year in roman numerals using PHP

mins

Roman numeral convertor function

<?php 
function numberToRomanRepresentation($number) {$map = array('M' => 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);$returnValue = '';while ($number > 0) {foreach ($map as $roman => $int) {if($number >= $int) {$number -= $int;$returnValue .= $roman;break;}}}return $returnValue;}
?> 

Print result

<?php 
/*** use the current year as the number to convert ***/
$year = date('Y');
/*** echo the roman numeral for the year ***/
echo numberToRomanRepresentation($year);
?>

Output: MMXXI

I do not use cookies on this website

🍪🍪 What cookies?


Your privacy is important. That's why this website doesn't track visitors with fingerprinting, your IP address or cookies.


Web analytics data is your own. Reclaim it.

Gain back control with a privacy-focused web analytics platform (using a cookie-less architecture) from: Data Centurion.