PHP | IntlChar getNumericValue() Function

The IntlChar::getNumericValue() function is an inbuilt function in PHP which is used to get the numeric value for a Unicode code point as defined in the Unicode Character Database.

Syntax:

float IntlChar::getNumericValue( $codepoint )

Parameters: This function accepts a single parameter $codepoint which is mandatory. The input parameter is a character, which is encoded as a UTF-8 string.



Return Value: This function returns the numeric value of codepoint on success, or IntlChar::NO_NUMERIC_VALUE if none is defined.

Below programs illustrate the IntlChar::getNumericValue() function in PHP:

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php 
// PHP program to illustrate the use of
// IntlChar::getNumericValue() Function
      
// Input int codepoint value 
var_dump(IntlChar::getNumericValue("2")); 
      
// Input int codepoint value 
var_dump(IntlChar::getNumericValue("4")); 
      
// Input char codepoint value 
var_dump(IntlChar::getNumericValue("G")); 
      
// Input string codepoint value 
var_dump(IntlChar::getNumericValue("Geeks")); 
  
// Input Symbolic codepoint value 
var_dump(IntlChar::getNumericValue("$")); 
  
// Input Symbolic codepoint value 
var_dump(IntlChar::getNumericValue("\u{216C}")); 
  
// Input Symbolic codepoint value 
var_dump(IntlChar::getNumericValue("\u{216F}")); 
  
?> 

chevron_right


Output:

float(2)
float(4)
float(-123456789)
NULL
float(-123456789)
float(50)
float(1000)

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php 
// PHP program to illustrate the use of 
// IntlChar::getNumericValue() Function 
  
// Declare an array with 
// different codepoint value 
$arr = array("4"
            "1",
            "Geeks",
            "\u{216C}"
            "\u{216F}"
            65, 
        ); 
      
// For loop condition to check 
// each character through function 
foreach ($arr as $val) { 
          
    // Check each element as code point data 
    var_dump(IntlChar::getNumericValue($val)); 
?> 

chevron_right


Output:

float(4)
float(1)
NULL
float(50)
float(1000)
float(-123456789)

Reference: http://php.net/manual/en/intlchar.getnumericvalue.php



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.