Open In App

PHP | IntlChar digit() function

The IntlChar::digit() function is an inbuilt function in PHP which is used to get the decimal digit value of a code point for a given radix. This function returns the decimal digit value of the code point in the specified radix.

Syntax:



int IntlChar::digit( $codepoint, $radix )

Parameters: This function accepts two parameters as mentioned above and described below:

Return Value: This function returns the number represented by the character in the given radix, or False if there is no value or if the value exceeds the radix.



Note: Valid and invalid function argument:

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

Program 1:




<?php
  
// PHP code to illustrate IntlChar::digit()
// function
  
// Input data is single digit
var_dump(IntlChar::digit("6"));
  
// Input data is single digit
var_dump(IntlChar::digit("3"));
  
// Input data is character type
var_dump(IntlChar::digit("A"));
  
// // Input data is character type with base
var_dump(IntlChar::digit("P", 16));
  
// // Input data is character type with base
var_dump(IntlChar::digit("9", 2));
?>

Output:
int(6)
int(3)
bool(false)
bool(false)
bool(false)

Program 2:




<?php
// PHP code to illustrate IntlChar::digit()
      
// Declare an array $arr
$arr = array("G", "GeeksforGeeks", "^", "1001", "6", "\n",
                                             "\n\n", "\t");
     
// Loop run for every array element
foreach ($arr as $val){
         
    // Check each element as code point data
    var_dump(IntlChar::digit($val));
}
?>

Output:
bool(false)
NULL
bool(false)
NULL
int(6)
bool(false)
NULL
bool(false)

Related Articles:

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


Article Tags :