PHP | IntlChar digit() function
Last Updated :
27 Aug, 2019
Improve
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:
php
php
int IntlChar::digit( $codepoint, $radix )Parameters: This function accepts two parameters as mentioned above and described below:
- $codepoint: The value of $codepoint is an integer or character, which is encoded as a UTF-8 string.
- $radix: It is optional parameter. Its default value is 10.
- If both $radix or $digit is not valid then return NULL.
- The $radix argument is valid if its value lies between $radix >= 2 and $radix <= 36.
- The digit is valid if its value is 0 <= digit < radix.
- The character has a decimal digit value. This characters comes under general category Nd(decimal digit numbers) and a Numeric_Type of Decimal.
- The character is uppercase Latin letters in between 'A' to 'Z'. Then the value of character is c-'A'+10.
- The character is lowercase Latin letters in between 'a' to 'z'. Then the value of character is ch-'a'+10.
- Latin letters from both the ASCII range (0061..007A, 0041..005A) as well as from the Full width ASCII range (FF41..FF5A, FF21..FF3A) are recognized.
<?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:
Program 2:
int(6) int(3) bool(false) bool(false) bool(false)
<?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:
Related Articles:
bool(false) NULL bool(false) NULL int(6) bool(false) NULL bool(false)
- PHP | IntlChar::isdigit() Function
- PHP | IntlChar::forDigit() Function
- PHP | IntlChar::charDigitValue() Function