PHP | IntlChar::forDigit()函数

这个 IntlChar::forDigit() 函数是PHP中的一个内置函数,用于确定指定基数中特定数字的字符表示形式。

null

语法:

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

参数: 该函数接受两个参数,如下所述:

  • 美元位数: 这是一个必需的参数。它是一个要转换为字符的数字。
  • $radix: 它是可选参数。其默认值为10。

返回值: 它返回指定基数中指定数字的字符表示形式。

注: 有效和无效的函数参数:

  • 如果$radix或$digit都无效,则返回NULL。
  • 如果基数参数的值介于$radix>=2和$radix<=36之间,则该参数有效。
  • 如果数字的值为0<=数字
  • 在数字情况下:数字<10,则返回“0”和+数字,否则返回“a”+数字-10。

下面的程序说明了 IntlChar::forDigit() PHP中的函数:

项目1:

<?php
// PHP function to illustrate
// the use of IntlChar::forDigit()
// Input int codepoint value
var_dump(IntlChar::forDigit(0));
// Input int codepoint value
var_dump(IntlChar::forDigit(1));
//Input int codepoint value
var_dump(IntlChar::forDigit(10));
// Input int codepoint value
var_dump(IntlChar::forDigit(10, 2018));
// Input float codepoint value
var_dump(IntlChar::forDigit(20999.1811));
?>


输出:

int(48)
int(49)
int(0)
int(0)
int(0)

项目2:

<?php
// PHP function to illustrate the
// use of IntlChar::forDigit()
// Declare an array with
// different codepoint value
$arr = array ( "7" ,
(50),
"8" ,
"0" ,
);
// For loop condition to check
// each character through function
foreach ( $arr as $val ) {
// Check each element as code point data
var_dump(IntlChar::forDigit( $val ));
}
?>


输出:

int(55)
int(0)
int(56)
int(48)

方案3: 下面是函数实现,如果传递参数符号或字符,则会给出一个错误。

<?php
// PHP function to illustrate
// the use of IntlChar::forDigit()
//Input char codepoint value
var_dump(IntlChar::forDigit( "Geeks" ));
//Input char codepoint value
var_dump(IntlChar::forDigit( "X" ));
//Input control codepoint value
var_dump(IntlChar::forDigit( "" ));
//Input symbolic  codepoint value
var_dump(IntlChar::forDigit( "@" ));
?>


输出:

E_WARNING

相关文章:

参考: http://php.net/manual/en/intlchar.fordigit.php

© 版权声明
THE END
喜欢就支持一下吧
点赞12 分享