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