search
Homephp教程php手册php判断是否为数字
php判断是否为数字 May 15, 2018 pm 03:26 PM

我们用intval来判断用户输入的信息是否为数字,这个可以自动转换成数字,如果是0,返回的值也是假的,在php判断用户输入的是否为数字型或是否为数字型字符串,我们会用到is_numeric与intval函数来处理.实例代码如下:

$num  = 1; 
$num1 ='1'; 
$str  ='abc'; 
if( is_numeric( $num ) ) 
{ 
    echo $num.'是数字型'; 
} 
//1是数字型 
if( is_numeric( $num1) ) 
{ 
    echo $num1.'是数字型'; 
} 
else 
{ 
    echo $num1.'不是数字型'; 
}

//1是数字型 

第二个实例为看还是数字型呢,这要看php是那类型的语言了,关键是php是弱语言型,所以就会自动把数字型字符转换成数字了,实例代码如下:

if( intval( $str ) ) 
{ 
    echo $str.'是数字'; 
} 
else 
{ 
    echo $str.'不是数字'; 
} 
//acd不是数字 
if( intval( $num1 ) ) 
{ 
    echo $num1.'是数字'; 
} 
else 
{ 
    echo $num1.'不是数字'; 
} 
//1是数字
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!