Php ctype_数字-奇怪的行为
我有一个Php ctype_数字-奇怪的行为,php,Php,我有一个数组,第一个13值是整数 现在,如果我这样做: array_push($pos1, 100); 我将指出值14也是一个整数。但事实上,做: echo ctype_digit($pos1[12])." - ".ctype_digit($pos1[13]); 输出为1- 这是按要求打印的文件: Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] =&
数组
,第一个13
值是整数
现在,如果我这样做:
array_push($pos1, 100);
我将指出值14
也是一个整数。但事实上,做:
echo ctype_digit($pos1[12])." - ".ctype_digit($pos1[13]);
输出为1-
这是按要求打印的文件:
Array ( [0] => 0
[1] => 1
[2] => 2
[3] => 3
[4] => 4
[5] => 5
[6] => 6
[7] => 7
[8] => 8
[9] => 9
[10] => 10
[11] => 11
[12] => 12
[13] => 100 )
为什么?这(事实上)有点奇怪,但严格来说需要字符串
echo ctype_digit((string) $pos1[12])." - ".ctype_digit((string) $pos1[13]); // "1 - 1"
我不知道,为什么PHP不把它转换成字符串
但是,输出中的1
来自类型转换,因为ctype\u digit()
返回布尔值
echo true; // "1"
echo false; // ""
这(事实上)有点奇怪,但严格来说需要一个字符串
echo ctype_digit((string) $pos1[12])." - ".ctype_digit((string) $pos1[13]); // "1 - 1"
我不知道,为什么PHP不把它转换成字符串
但是,输出中的1
来自类型转换,因为ctype\u digit()
返回布尔值
echo true; // "1"
echo false; // ""
是,因为函数严格要求字符串。您得到的输出1-
仅仅是因为PHP处理其
echo ctype_digit($pos1[12])." - ".ctype_digit($pos1[13]);
作为
echo ctype_位($pos1[12])代码>//输出为TRUE
FALSE因为在数组中前13个值是整数,第14个值不是整数。是因为ctype\u digit()
函数严格要求字符串。您得到的输出1-
仅仅是因为PHP处理其
echo ctype_digit($pos1[12])." - ".ctype_digit($pos1[13]);
作为
echo ctype_位($pos1[12])代码>//输出为TRUE
FALSE因为在数组中前13个值是整数,第14个值不是整数。可以显示完整数组的打印\r
吗?在使用ctype\u digit
之前,print\r($pos1)
包含哪些内容,打印什么?编辑主题:您可以显示完整数组的打印内容吗?使用ctype\u digit
之前,$pos1
包含什么内容?尝试打印($pos1)
,打印什么?编辑主题:您可以显示打印内容吗