$num = 1234567890; echo number_format($num); //1,234,567,890 echo number_format($num,2); //1,234,567,890.00 echo number_format($num,2,'-',''); //1,234,567,890-00
$num = 1234567890; function thousandsSplit($num){ //反轉字符串 0987654321 $num = strrev($num); //使用逗號分割字符串 098,765,432,1, $num = chunk_split($num, 3, ','); //再次反轉字符串 ,1,234,567,890 $num = strrev($num); //去除最左邊的逗號 1,234,567,890 $num = ltrim($num, ','); echo $num; //輸出 1,234,567,890 }