What is the function in PHP that can be used 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. By providing the number to format and the desired decimal places as arguments, you can easily achieve the desired formatting.

$number = 123.456789;
$decimalPlaces = 2;

$formattedNumber = number_format($number, $decimalPlaces);
echo $formattedNumber; // Output: 123.46