Differences between is_numeric and ctype_digit in PHP _ PHP Tutorial

Source: Internet
Author: User
Differences between is_numeric and ctype_digit in PHP. Is_numeric: Check whether the string is a numeric string. if it can be a negative number or a decimal number, ctype_digit: check whether all characters in the string are numbers. if it is a negative number or a decimal number, check whether the parameter is is_numeric: checks whether it is a numeric string, which can be a negative number or a decimal number.

Ctype_digit: checks whether all characters in a string are numbers. negative and decimal digits cannot be detected.

Note that the parameter must be a string. if it is not a string, 0/FASLE is returned.

The following is a test example:

The code is as follows:


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

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

$ A =;
Var_dump ($ );
Var_dump (is_numeric ($ a); // false
Var_dump (ctype_digit ($ a); // false

Ctype_digit: checks whether all characters in a string are numbers. negative numbers and decimals cannot be detected. the parameter must be...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.