How can the number_format() function be used in PHP to format decimal values?

To format decimal values in PHP, the number_format() function can be used. This function takes a numeric value as its first parameter and optional parameters for the number of decimal places, decimal separator, and thousands separator. By using number_format(), you can easily format decimal values for display purposes in PHP.

// Example usage of number_format() to format a decimal value
$number = 1234.5678;
$formatted_number = number_format($number, 2, '.', ',');
echo $formatted_number; // Output: 1,234.57