我有一个array,第一个13值是integer。
现在,如果我做了:
array_push($pos1, 100);我将考虑值14也是一个Integer。但事实上,做:
echo ctype_digit($pos1[12])." - ".ctype_digit($pos1[13]);输出为1 -
这是print_r,根据请求:
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 )为什么?
发布于 2011-05-11 10:36:23
这(实际上)有点奇怪,但是数字()严格地要求一个字符串
echo ctype_digit((string) $pos1[12])." - ".ctype_digit((string) $pos1[13]); // "1 - 1"我不知道,为什么PHP不把它转换成字符串。
但是,输出中的1来自类型转换,因为ctype_digit()返回布尔值。
echo true; // "1"
echo false; // ""发布于 2013-02-25 10:07:55
是的,因为ctype_digit()函数严格要求字符串。您得到的输出1-仅仅是因为
echo ctype_digit($pos1[12])." - ".ctype_digit($pos1[13]);作为
echo ctype_digit($pos1[12]); //使输出为真
echo " - " ; //Giving output * - *
echo ctype_digit($pos1[13]);FALSE,因为在数组中,前13个值是整数,第14个值不是整数。
https://stackoverflow.com/questions/5962529
复制相似问题