3 回答
TA贡献1795条经验 获得超7个赞
// $a = array("1"=>2,"2"=>8,"3"=>9,"4"=>8,"5"=>6,"6"=>7,"7"=>9,"8"=>2); // used short array notation (see references) and removed keys (since not used)
$numbers = [2,8,9,8,6,7,9,2,95890814984141]; // the last number is for my pleasure :P
$numberFormatter = new NumberFormatter('en', NumberFormatter::SPELLOUT);
foreach ($numbers as $number) {
$numberSpelled = $numberFormatter->format($number);
$numberSpelledWithFirstCharUpper = ucfirst($numberSpelled);
echo $numberSpelledWithFirstCharUpper . ' - ' . $number . PHP_EOL;
}
输出
Two - 2
Eight - 8
Nine - 9
Eight - 8
Six - 6
Seven - 7
Nine - 9
Two - 2
Ninety-five trillion eight hundred ninety billion eight hundred fourteen million nine hundred eighty-four thousand one hundred forty-one - 95890814984141
工作示例。
TA贡献1783条经验 获得超4个赞
array_map()
是的,您必须为此创建另一个数组或将值放在现有数组上,但如果您不使用此方法,那么这将是很好的练习。
foreach($a as $key=>$value) { echo $b[$key]."-".$value."<br>";
- 3 回答
- 0 关注
- 94 浏览
添加回答
举报