How can a number be formatted in PHP to display in a specific format?
To format a number in PHP to display in a specific format, you can use the number_format() function. This function allows you to specify the number of decimal places, thousands separator, and decimal separator. By using number_format(), you can easily format numbers according to your desired format.
$number = 1234567.89;
$formatted_number = number_format($number, 2, '.', ',');
echo $formatted_number; // Output: 1,234,567.89