阿拉伯数字 转换 中文大写 money = round( $money , 2 ); } private function cnyMapUnit( $list , $units ) { $ul = count($units); $xs = array(); $list = array_reverse($list); while( list($keys , $vals) = each($list) ){ $l = count($xs)
money = round( $money , 2 ); } private function cnyMapUnit( $list , $units ) { $ul = count($units); $xs = array(); $list = array_reverse($list); while( list($keys , $vals) = each($list) ){ $l = count($xs); if ($vals != "0" || !($l%4) ){ $val = $vals . ( $units[ ($l-1)%$ul ] ); }else{ $val = is_numeric( $xs[0][0] ) ? $vals : ''; } array_unshift( $xs , $val ); } return $xs; } public function arr( $leng=0 , $suffix=false ){ list( $int , $dec ) = explode( "." , $this->money , 2 ); $cnygrees = $this->cnygrees; $cnynums = array_keys($this->cnynums); $temp = array(); $index = 0; if( $leng > 0 && $suffix !== false ){ for( $i=0; $i<$leng; $i++){ $cnygrees[$i] = $suffix; } } $data = $this->cnyMapUnit( str_split($int) , $cnygrees ); $data = array_reverse( $data ); while( list( $key , $val ) = each( $data ) ){ $val = str_replace( $cnynums , $this->cnynums , $val ); if( empty( $temp[ $index ] ) ){ $temp[ $index ] = ''; } $temp[ $index ] = $val . $temp[ $index ]; $index++; if( $index > $leng ){ $index = $leng; } } return array_reverse( $temp ); } } $to = new ToChineseNumber( 1892600 ); $to->arr( 4 , ''); // Array // ( // [0] => 壹佰捌拾玖 // [1] => 贰 // [2] => 陆 // [3] => 零 // [4] => 零 // )QQ截图20170909154439.jpg