money_format() Function in PHP 7.4 With Example

Support PHP Version: PHP 7.1, PHP 7.2, PHP 7.3, PHP 7.4, PHP 8.0, PHP 8.1, PHP 8.2, PHP 8.3 With Latest All Version Support.

The `money_format()` function in PHP is used to format a number as a currency string based on a specified format. However, as of PHP 7.4, `money_format()` function is deprecated. Therefore, it’s not available in PHP 8.2. Instead, you can use `number_format()` function along with appropriate formatting to achieve similar results. Here’s an example:


// Define a number
$number = 1234.56;

// Format the number as currency using number_format() function
$formatted = number_format($number, 2, '.', ',');

// Add currency symbol and any other necessary formatting
$currency = '$' . $formatted;

// Output the formatted currency
echo $currency; // Output: $1,234.56


In this example:

1. `number_format()` is used to format the number.
2. The first argument is the number to be formatted.
3. The second argument specifies the number of decimal points.
4. The third argument is the decimal point separator.
5. The fourth argument is the thousands separator.