3 回答
TA貢獻(xiàn)1795條經(jīng)驗(yàn) 獲得超7個(gè)贊
// $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貢獻(xiàn)1783條經(jīng)驗(yàn) 獲得超5個(gè)贊
array_map()是的,您必須為此創(chuàng)建另一個(gè)數(shù)組或?qū)⒅捣旁诂F(xiàn)有數(shù)組上,但如果您不使用此方法,那么這將是很好的練習(xí)。
foreach($a as $key=>$value) {
echo $b[$key]."-".$value."<br>";- 3 回答
- 0 關(guān)注
- 166 瀏覽
添加回答
舉報(bào)
