Home  >  Article  >  Backend Development  >  Introduction to the difference between digital detection is_numeric and ctype_digit in PHP_PHP Tutorial

Introduction to the difference between digital detection is_numeric and ctype_digit in PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 15:15:34858browse

is_numeric: Check whether it is a numeric string, it can be negative numbers and decimals

ctype_digit: Check whether the characters in the string are all numbers, negative numbers and decimals will fail the test

Note, the parameters must be certain If it is a string, if it is not a string, 0/FASLE will be returned

The following is a test example:

Copy code Code As follows:

$a = 0001111222;
var_dump($a);
var_dump(is_numeric($a)); //true
var_dump(ctype_digit($a) ); //true
$a = 0.1 ;
var_dump($a);
var_dump(is_numeric($a)); //true
var_dump(ctype_digit($a)); / /false

$a = -1 ;
var_dump($a);
var_dump(is_numeric($a)); //true
var_dump(ctype_digit($a)); //false

$a = a ;
var_dump($a);
var_dump(is_numeric($a)); //false
var_dump(ctype_digit($a)); //false

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326088.htmlTechArticleis_numeric: Check whether it is a numeric string, which can be negative numbers and decimals ctype_digit: Check whether the characters in the string are all It is a number. Negative numbers and decimals will fail the detection. Note that the parameters must be...
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