PHP String localeconv() Function

The localeconv() function is the in-built function of PHP. It is used to get numeric information. This function returns an array which contains local numeric and monetary formatting information. This function is a non-parameterized function, so we do not need to pass anything in this function.

Syntax

The basic syntax of the localeconv() function of PHP is:

Parameter

No parameter is required in localeconv() function.

Value returned by localeconv()

This function returns the data based upon the current locale, which is set by setlocale() function. An associative array is returned which contains the following fields:

Array ElementsDescription
decimal_pointIt represents the decimal point character.
thousand_sepIt represents the thousands separator.
groupingArray containing numeric groupings. Array displays how numbers are grouped. E.g., 1 000 000
int_curr_symbolIt is International Currency Symbol, i.e., USD
currency_symbolIt is local currency symbol, i.e., $
mon_decimal_pointIt represents the Monetary decimal point character
mon_thousands_sepIt represents the Monetary thousands separator
Mon_groupingArray containing monetary grouping. Array displays how monetary numbers are grouped. E.g., 1 00 00 00
positive_signIt is the sign for the positive value.
negative_signIt is the sign for the negative value.
int_frac_digitsIt is the International fractional digits.
frac_digitsIt is local fractional digits
p_cs_precedesIt will be TRUE (1) if currency_symbol precedes a positive value and FALSE (0) if it succeeds one.
n_cs_precedesIt will be TRUE (1) if currency_symbol precedes a negative value and FALSE (0) if it succeeds one.
P_sep_by_spaceIt will be TRUE (1) if a space separates currency_symbol from a positive value, otherwise it will be FALSE (0).
n_sep_by_spaceIt will be TRUE (1) if a space separates currency_symbol from a negative value, otherwise it will be FALSE (0).
p_sign_posn0 - Parentheses surrounds the quantity and currency_symbol.
1 - The + sign string precedes the currency symbol and quantity.
2- The + sign string succeeds the quantities and currency_symbol.
3 - The + sign string immediately precedes the currency symbol.
4 - The + sign string immediately succeeds the currency symbol.
n_sign_posn0 - Parentheses surrounds the quantity and currency_symbol.
1 - The - sign string precedes the currency symbol and quantity.
2 - The - sign string succeeds the quantities and currency_symbol.
3 - The - sign string immediately precedes the currency symbol.
4 - The - sign string immediately succeeds the currency symbol.

Note: The p_sign_posn and n_sign_posn contain a string of formatting options, and each number represents one of the above-listed condition.

Example

Below some examples are given to understand the localeconv() function in a much better way:

Example 1

Output:

PHP String localeconv() Function

The above output will be shown like this in view source.

Array
(
    [decimal_point] => .
    [thousands_sep] => ,
    [int_curr_symbol] => USD
    [currency_symbol] => $
    [mon_decimal_point] => .
    [mon_thousands_sep] => ,
    [positive_sign] => 
    [negative_sign] => -
    [int_frac_digits] => 2
    [frac_digits] => 2
    [p_cs_precedes] => 1
    [p_sep_by_space] => 0
    [n_cs_precedes] => 1
    [n_sep_by_space] => 0
    [p_sign_posn] => 3
    [n_sign_posn] => 0
    [grouping] => Array
        (
            [0] => 3
        )
    [mon_grouping] => Array
        (
            [0] => 3
        )
)

Example 2

Output:

PHP String localeconv() Function

Below is the view source of the above program. With the help of this output representation, we can easily see the difference among different examples.

Array
(
    [decimal_point] => .
    [thousands_sep] => 
    [int_curr_symbol] => USD
    [currency_symbol] => $
    [mon_decimal_point] => .
    [mon_thousands_sep] => ,
    [positive_sign] => 
    [negative_sign] => -
    [int_frac_digits] => 2
    [frac_digits] => 2
    [p_cs_precedes] => 1
    [p_sep_by_space] => 0
    [n_cs_precedes] => 1
    [n_sep_by_space] => 0
    [p_sign_posn] => 3
    [n_sign_posn] => 0
    [grouping] => Array
        (
        )

    [mon_grouping] => Array
        (
            [0] => 3
        )
)

Example 3

Output:

PHP String localeconv() Function
Array
(
    [decimal_point] => .
    [thousands_sep] => ,
    [int_curr_symbol] => 
    [currency_symbol] => 
    [mon_decimal_point] => 
    [mon_thousands_sep] => 
    [positive_sign] => 
    [negative_sign] => 
    [int_frac_digits] => 127
    [frac_digits] => 127
    [p_cs_precedes] => 127
    [p_sep_by_space] => 127
    [n_cs_precedes] => 127
    [n_sep_by_space] => 127
    [p_sign_posn] => 127
    [n_sign_posn] => 127
    [grouping] => Array
        (
            [0] => 3
        )

    [mon_grouping] => Array
        (
        )
)

Example 4

Output:

PHP String localeconv() Function
Array
(
    [decimal_point] => .
    [thousands_sep] => 
    [int_curr_symbol] => 
    [currency_symbol] => 
    [mon_decimal_point] => 
    [mon_thousands_sep] => 
    [positive_sign] => 
    [negative_sign] => 
    [int_frac_digits] => 127
    [frac_digits] => 127
    [p_cs_precedes] => 127
    [p_sep_by_space] => 127
    [n_cs_precedes] => 127
    [n_sep_by_space] => 127
    [p_sign_posn] => 127
    [n_sign_posn] => 127
    [grouping] => Array
        (
        )

    [mon_grouping] => Array
        (
        )
)

Here, you can see the changes in each and every output of the example.

Note: To understand the working of setlocale() function follow the given link https://www.javatpoint.com/php-string-setlocale-function.






Latest Courses