PHP 中的 ctype_digit()函数

首页 / PHP入门教程 / PHP 中的 ctype_digit()函数

ctype_digit() - 语法

ctype_digit ( $text );

它检查提供的字符串text中的所有字符是否都是数字的。它只检查1.9

Sr.No Parameter & Description
1

text(必需)

匹配字符串。

ctype_digit() - 返回值

如果文本中的每个字符都是十进制数字,则返回TRUE,否则返回FALSE。

链接:https://www.learnfk.comhttps://www.learnfk.com/php/php-function-ctype-digit.html

来源:LearnFk无涯教程网

ctype_digit() - 示例

<?php
   $strings=array('122.50', '1004', 'foo!#$bar');
   
   foreach ($strings as $test) {
      if (ctype_digit($test)) {
         echo "$test consists of all digits.\n";
      }else {
         echo "$test does not have all digits.\n";
      }
   }
?> 

这将产生以下结果-

122.50 does not have all digits
1004 consists of all digits
foo!#$bar does not have all digits

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

人工智能基础课 -〔王天一〕

玩转webpack -〔程柳锋〕

TypeScript开发实战 -〔梁宵〕

性能工程高手课 -〔庄振运〕

RPC实战与核心原理 -〔何小锋〕

技术面试官识人手册 -〔熊燚(四火)〕

陈天 · Rust 编程第一课 -〔陈天〕

徐昊 · TDD项目实战70讲 -〔徐昊〕

手把手带你写一个MiniSpring -〔郭屹〕

好记忆不如烂笔头。留下您的足迹吧 :)