How can PHP be used to format decimal numbers with a specific number of decimal places?

When formatting decimal numbers with a specific number of decimal places in PHP, you can use the number_format() function. This function allows you to specify the number of decimal places you want to display for a given number. By providing the number, the desired decimal places, and the decimal point and thousands separator characters as arguments to the function, you can easily format decimal numbers as needed.

$number = 123.456789;
$decimal_places = 2;
$formatted_number = number_format($number, $decimal_places, '.', ',');
echo $formatted_number; // Output: 123.46