我想像这样用空格分隔数字:1 200,12 500或2 000 000而不是2000000 ...
function show_price($id) {
global $currency_a;
if(get_option("defaultcurrency")) {
$curr = $currency_a[get_option("defaultcurrency")][2];
} else {
$curr = $currency_a[get_post_meta($id, "currency", true)][2];
}
$price = get_post_meta($id, "price", true);
$currpos = get_option("currpos");
if($currpos == "1" || !$currpos) {
return $price."".$curr;
} elseif ($currpos == "2") {
return $curr."".$price;
} elseif ($currpos == "3") {
return $price;
}
}
Run Code Online (Sandbox Code Playgroud)
PHP为此具有自己的功能: number_format()
http://php.net/manual/zh/function.number-format.php
只需将$ thousands_sep参数设置为空白而不是默认值即可。例如:
number_format($number, 0, '.', ' ');
Run Code Online (Sandbox Code Playgroud)