php实现阿拉伯数字和罗马数字相互转换的方法_php技巧
程序员文章站
2022-06-08 10:14:30
...
本文实例讲述了php实现阿拉伯数字和罗马数字相互转换的方法。分享给大家供大家参考。具体如下:
3999 || $f 1000, 'D' => 500, 'C' => 100, 'L' => 50, 'X' => 10, 'V' => 5, 'I' => 1 ); // Calculate the needed roman figures: foreach($roman as $k => $v) if(($amount[$k] = floor($f / $v)) > 0) $f -= $amount[$k] * $v; // Build the string: $return = ''; foreach($amount as $k => $v) { $return .= $v 1000, 'D' => 500, 'C' => 100, 'L' => 50, 'X' => 10, 'V' => 5, 'I' => 1 ); // Convert the string to an array of roman values: for($i = 0; $i $current ? $sum += $next - $current + 0 * next($values) : $sum += $current; } // Return the value: return $sum; } // echo roman2dec(IX); ?>
希望本文所述对大家的php程序设计有所帮助。