Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要一个 PHP 函数来格式化 Facebook“喜欢”之类的数字。
例子:
12345 = 12,3 千
123456 = 123 千
1234567 = 1,23 M
谢谢!!
写一个函数来做这个!?
function format_num($n) { $s = array("K", "M", "G", "T"); $out = ""; while ($n >= 1000 && count($s) > 0) { $n = $n / 1000.0; $out = array_shift($s); } return round($n, max(0, 3 - strlen((int)$n))) ." $out"; }
我一直是一个编写干净易读的代码的人。话虽如此,我无法确定使用更多或更少<?php标签时处理速度是否有任何差异。下面是一些代码进行比较:
<?php
首选代码:
<?php while($condition): ?> <?php if($anotherCondition): ?&g