What PHP function can be used to format numbers with commas and decimals?
To format numbers with commas and decimals in PHP, you can use the number_format() function. This function takes a number as its first argument and optionally accepts two additional arguments for the number of decimal places and the characters used for decimal points and thousands separators. By using number_format(), you can easily format numbers to include commas for thousands separators and specify the number of decimal places.
$number = 1234567.89;
$formatted_number = number_format($number, 2, '.', ',');
echo $formatted_number; // Output: 1,234,567.89