What are the recommended PHP functions or methods to format numbers with commas in a specific way?

When formatting numbers with commas in PHP, you can use the number_format() function. This function allows you to specify the number of decimal places, the thousands separator (comma in this case), and the decimal separator. By using number_format(), you can easily format numbers in a specific way with commas.

$number = 1234567.89;
$formatted_number = number_format($number, 2, '.', ',');
echo $formatted_number; // Output: 1,234,567.89