What is the best way to convert a number in PHP to include a comma as a decimal separator?

When converting a number in PHP to include a comma as a decimal separator, you can use the number_format() function. This function allows you to format a number with grouped thousands and specify the number of decimal places. By setting the decimal point parameter to a comma, you can achieve the desired format.

$number = 12345.67;
$formatted_number = number_format($number, 2, ',', '.');
echo $formatted_number; // Output: 12.345,67