Need to add comma after every 3 digits using php

php

Solution

Edit:

as another answer suggested, there is a simple way to do this using `number_format`:

echo number_format(1234); // 1,234

Original answer:

try this `str_split`

$price = 1234;

$price_text = (string)$price; // convert into a string
$price_text = strrev($price_text); // reverse string
$arr = str_split($price_text, "3"); // break string in 3 character sets

$price_new_text = implode(",", $arr);  // implode array with comma
$price_new_text = strrev($price_new_text); // reverse string back
echo $price_new_text; // will output 1,234

Problem

I am using cms - megento. I want to display the price value in following format : add comma after every 3 digits. for example : ``` $price = 987536453 ; Need to print like 987,536,453. ```

Original source