What is the best way to format numbers in PHP to include commas for thousands separators?
When working with large numbers in PHP, it is common to format them with commas as thousands separators to improve readability. One way to achieve this is by using the number_format() function in PHP. This function takes the number as its first argument and the number of decimal places as its second argument, and returns a formatted string with commas as thousands separators.
$number = 1000000;
$formatted_number = number_format($number);
echo $formatted_number; // Output: 1,000,000