localeconv() Function Use in PHP 8.5

The localeconv() function works the same way in PHP 8.5 as it did in previous versions. It returns an associative array containing the localized numeric and monetary formatting rules (like decimal points, thousands separators, and currency symbols) based on the current locale set by setlocale().

Function Signature

localeconv(): array
It takes no parameters and always returns an array.

Example

It is important to call setlocale() first; otherwise, the default "C" locale returns mostly empty or useless values.

<?php
// Set the locale to US English
setlocale(LC_ALL, en_US.UTF-8 );

// Get the formatting rules
$locale_info = localeconv();

// Display specific formatting rules
echo "Decimal Point: " . $locale_info[ decimal_point ] . " ";
echo "Thousands Separator: " . $locale_info[ nothousands_sep ] . " ";
echo "Currency Symbol: " . $locale_info[ currency_symbol ] . " ";
echo "Fraction Digits: " . $locale_info[ frac_digits ] . " ";
?>

Output:

Decimal Point: .
Thousands Separator: ,
Currency Symbol: $
Fraction Digits: 2

5 Views