Tách số theo hàng nghìn nhìn cho dễ

<?php
function formatPrice($value) {
    $value = strval(intval($value));
    $temp = strrev($value);
    $len = strlen($temp);
    $ret = ”;
    for ($i = 0; $i < $len; $i++) {
        $ret .= $temp[$i];
        if ($i % 3 == 2 && $i < $len – 1) $ret .= ‘,’;
    }
    return strrev($ret);
}

echo formatPrice(20000000); // output: 20,000,000