What function can be used in PHP to format numbers with a specific number of decimal places?

To format 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. Simply pass the number you want to format and the desired decimal places as arguments to the function.

$number = 123.456789;
$decimal_places = 2;

$formatted_number = number_format($number, $decimal_places);

echo $formatted_number; // Output: 123.46