PHP Chinese Broadcast Amount

Source: Internet
Author: User

The following code is written because the project uses Aurora push to broadcast the amount that the user consumes.

Premise 1: Broadcast audio

Premise 2: Aurora push

Resolution 1: The Chinese amount is broadcast

Problem Solving 2:10100 trillion and zero broadcast

If there is a better way please leave a message, we learn from each other ha!

On the code:

Private Function Duqu ($total _fee = 0) {
if (Empty ($total _fee)) return false;
Set 0十百千万亿
$array = Array (' 0 ' = ' 0 ', ' 1 ' = ' + ', ' 2 ' = ' + ', ' 3 ' = ' + ', ' 4 ' = ' + ', ' 5 ' = ' ' 10,30 ', ' 6 ' = ' 29,30 ', ' 7 ' = ' 32,30 ', ' 8 ' = ' 31 ');
Dividing an amount by points into an array
$number = Explode ('. ', $total _fee);
$data = Array ();
foreach ($number as $k = = $v) {
$arr = Str_split ($v);
Operations before a point
if ($k = = 0) {
$flag = $KK = 0;
Krsort ($arr);
foreach ($arr as $k 1 = $v 1) {
$kk + +;
if ($kk = = 1 && $v 1! = 0) {
$data [$k] = $v 1;
}else if ($v 1! = 0) {
if ($flag! = 0 &&!empty ($data [$k]) {
$data [$k] = $array [0];
$flag = 0;
} else if ($flag! = 0 && empty ($data [$k])) {
$flag = 0;
}
if ($v 1 = = 1 && $k 1 = = 0 && ($KK-1 = 1)) {
$data [$k] = $array [$KK-1];
} else {
$data [$k] = $v 1. ', '. $array [$kk-1];
}
} else {
if ($k 1 < 8) {
$flag = $flag + 1;
}
}
}
Krsort ($data [$k]);
} else {//points after the operation
foreach ($arr as $k 1 = $v 1) {
$data [$k] = $v 1;
}
}
$data [$k] = implode (', ', $data [$k]);
}
Unset ($arr);
Unset ($array);
Unset ($flag);
Unset ($KK);
Add dots and Merge
if (empty ($data [0])) {
$data [0] = ' 0,11 ';
} else if (!empty ($data [1])) {
$data [0]. = ', 11 ';
}
$res = Implode (', ', $data);
$res. = ', 27 '; Yuan
return $res;
}

PHP Chinese Broadcast Amount

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.