3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * 数字转中文 * 数字在999999999999以下 * 数字够大的时候小数点后会取整,奇怪了 * @param string $number 无序数组 * @return string $str 有序数组 */ function number2cn($number) { if(!is_numeric($number)) { return "非数字"; } elseif($number > 999999999999 || $number < -999999999999) { return "数字超出范围"; } $p = explode(".",$number); $cn_arr = array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖"); $p_arr = array("","拾","佰","仟"); $unit_arr = array("","萬","億"); $str = ""; $zero = false;//零标志 $unit = "";//单位 //处理小数点后数字 if(isset($p[1])) {//小数点后有数字存在 $dot = "點"; $l = strlen($p[1]); for($i=0;$i<$l;$i++) { $dot .= $cn_arr[$p[1]{$i}]; } } else { $dot = ""; } $number = $p[0]; //小数点前数字 $l = strlen($number);//数字位数 for($i=$l-1,$j=0;$i>=0;$i--,$j++) { $pos = $number{$i}; if($pos=="-") { $str = "負".$str; break; } if($j%4==0) { $unit = $unit_arr[$j/4]; } if($pos == '0') { $zero = true; continue; } if($zero) { if($str != "") { $str = $cn_arr[$pos].$p_arr[$j%4].$unit.$cn_arr[0].$str; } else { $str = $cn_arr[$pos].$p_arr[$j%4].$unit; } $zero = false; } else { $str = $cn_arr[$pos].$p_arr[$j%4].$unit.$str; } $unit = ""; } return $str.$dot; } //示例 header('Content-Type: text/html; charset=utf-8'); $n = -9000000009.99; echo number2cn($n)."<br>";
Output for git.master, git.master_jit
Fatal error: Array and string offset access syntax with curly braces is no longer supported in /in/NEOAR on line 33
Process exited with code 255.
Output for rfc.property-hooks
Parse error: syntax error, unexpected token "{", expecting "]" in /in/NEOAR on line 33
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
43.33 ms | 401 KiB | 8 Q