
ctype_digit() 函数检测字符串里面的字符是不是都是数字。
语法
ctype_digit ( $text );
定义和用法
它检查提供的字符串,文本中的所有字符是否都是数字。它仅检查1 ... 9
参数
| 序号 | 参数及说明 | 
|---|---|
| 1 | text(必需) 需要被测试的字符串。 | 
返回值
如果文本中的每个字符都是十进制数字,则返回TRUE,否则返回FALSE。
在线示例
检测数组中的元素,元素是否是纯数字
<?php
   $strings = array('122.50', '1004', 'foo!#$bar');
   
   foreach ($strings as $test) {
      if (ctype_digit($test)) {
         echo "$test 字符全部为数字 \n";
      }else {
         echo "$test 包含非数字字符 \n";
      }
   }
?>测试看看‹/›输出结果:
122.50 包含非数字字符 1004 字符全部为数字 foo!#$bar 包含非数字字符
