Converting Decimal Number lying between 1 to 3999 to Roman Numerals | Function to calculate roman equivalent ; storing roman values of digits from 0 - 9 when placed at different places ; Converting to roman ; Driver Code
< ? php function intToRoman ( $ num ) { $ m = array ( " " , " M " , " MM " , " MMM " ) ; $ c = array ( " " , " C " , " CC " , " CCC " , " CD " , " D " , " DC " , " DCC " , " DCCC " , " CM " ) ; $ x = array ( " " , " X " , " XX " , " XXX " , " XL " , " L " , " LX " , " LXX " , " LXXX " , " XC " ) ; $ i = array ( " " , " I " , " II " , " III " , " IV " , " V " , " VI " , " VII " , " VIII " , " IX " ) ; $ thousands = $ m [ $ num / 1000 ] ; $ hundereds = $ c [ ( $ num % 1000 ) / 100 ] ; $ tens = $ x [ ( $ num % 100 ) / 10 ] ; $ ones = $ i [ $ num % 10 ] ; $ ans = $ thousands . $ hundereds . $ tens . $ ones ; return $ ans ; } $ number = 3549 ; echo intToRoman ( $ number ) ;