Home > php教程 > php手册 > php实现阿拉伯数字和罗马数字相互转换的方法

php实现阿拉伯数字和罗马数字相互转换的方法

WBOY
Release: 2016-06-06 20:04:54
Original
809 people have browsed it

这篇文章主要介绍了php实现阿拉伯数字和罗马数字相互转换的方法,涉及php字符串操作的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下

本文实例讲述了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程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template