How can you use the number_format function in PHP to achieve the desired formatting of numbers?

The number_format function in PHP is used to format numbers with specified decimal points, thousands separators, and decimal separators. To achieve the desired formatting of numbers, you can use number_format by passing the number you want to format as the first argument, the number of decimal points as the second argument, the decimal separator as the third argument, and the thousands separator as the fourth argument.

$number = 12345.6789;
$formatted_number = number_format($number, 2, '.', ',');
echo $formatted_number; // Output: 12,345.68