+

PHP IntlChar digit () function

Syntax:
int IntlChar::digit ($codepoint, $radix)
Parameters:this function takes two parameters as above and described below:
  • $codepoint:$codepoint is an integer or a character that is encoded as a UTF-8 string.
  • $radix:This is an optional parameter. Its default value is 10.
Return Value:This function returns the number represented by the character in the given radix, or False if there is no value or the value is greater than the radix.Note.Valid and invalid function argument:
  • If both are $radix or $digit invalid, return NULL.
  • $radix is valid if it is between $radix > = 2 and $radix
  • A digit is valid if its value is 0
  • The character has a decimal value. This symbol belongs to the general category Nd (decimal digits) and Numeric_Type of Decimal.
  • The symbol consists of uppercase Latin letters between "A" and "Z". Then the value of the character c is ` A ` + 10.
  • The character consists of lowercase Latin letters between "a" and "z". Then the value of the ch character is ` a ` + 10.
  • Latin letters from the ASCII range (0061..007A, 0041..005A), as well as from the full-width ASCII range ( FF41..FF5A, FF21..FF3A).
The following programs illustrate the IntlChar::digit() functionin PHP:Program 1:  
// PHP code for illustration IntlChar::digit()
// function 
// Input data consists of one digit var_dump (IntlChar::digit ( "6" ));  
// Input data consists of one digit var_dump (IntlChar::digit ( "3" ));  
// Input data is of character type var_dump (IntlChar::digit ( "A" ));  
// // Input data - character type with radix var_dump (IntlChar::digit ( "P" , sixteen));  
// // Input data - character type with radix var_dump (IntlChar::digit ( "9" , 2)); ?>
Exit:
int (6 ) int (3) bool (false) bool (false) bool (false)
Program 2:
// PHP code for illustration IntlChar::digit() 
// Declare the $arr array $arr = array ( " G " , " GeeksforGeeks " , "^" , "1001" , "6" , "" , "" , "" );  
// run loop for each array element foreach ( $arr as $val ) { // Validate each element as code point data var_dump (IntlChar::digit ( $val )); }
?>
Exit:
bool (false ) NULL bool (false) NULL int (6) bool (false) NULL bool (false)
Related Articles:
  • PHP | IntlChar::isdigit() function
  • PHP | IntlChar::forDigit() Function
  • PHP | IntlChar::charDigitValue() function
Link: http://php.net/manual/en/intlchar.digit.php
Get Solution for free from DataCamp guru