How can I format a number in PHP to display with commas as thousands separators?

To format a number in PHP to display with commas as thousands separators, you can use the number_format() function. This function takes the number you want to format as the first parameter and additional parameters for decimal points and separators. By specifying 0 for the decimal points and ',' for the thousands separator, you can easily format the number as desired.

$number = 10000;
$formatted_number = number_format($number, 0, ',', ',');
echo $formatted_number; // Output: 10,000