How can PHP be used to format numbers with thousand separators and decimals?

To format numbers with thousand separators and decimals in PHP, you can use the number_format() function. This function takes a number as the first parameter, the number of decimal places as the second parameter, the character to use as the decimal point as the third parameter, and the character to use as the thousand separator as the fourth parameter. By using this function, you can easily format numbers in the desired way.

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