Home > Article > Backend Development > How to use the PHP Is_Numeric() function
The is_numeric() function in the PHP programming language is used to calculate whether a value is a number or a numeric string. Numeric strings contain any number of digits, optional symbols (such as or -), optional decimals, and optional exponents. Therefore, 234.5e6 is a valid numeric string. Binary notation and hexadecimal notation are not allowed.
The is_numeric() function can be used in an if() statement to handle numbers in one way and non-numbers in another way. It returns true or false.
Example of Is_Numeric() function
For example:
<?php if (is_numeric(887)) { echo "Yes"; } else { echo "No"; } ?>
Because 887 is a number, this output is. However:
<?php if (is_numeric("cake")) { echo "Yes"; } else { echo "No"; } ?>
Because cake is not a number, this output is not available.
Similar functions
The similar function ctype-digit() also checks for numeric characters, but only for digits—no signs, decimals, or exponents are allowed. Each character in the string literal must be a decimal number for true to be returned. Otherwise, the function returns false.
Other similar functions include:
is_null() - 查找变量是否为NULL is_float() - 查找变量的类型是否为float is_int() - 查找变量的类型是否为整数 is_string() - 查找变量的类型是否为字符串 is_object() - 查找变量是否为对象 is_array() - 查找变量是否为数组 is_bool() - 查找变量是否为布尔值
Note: About PHP
PHP is the abbreviation of Hypertext Preprocessor. It is an open source HTML-friendly scripting language used by website owners to write dynamically generated pages. The code is executed on the server and generates HTML, which is then sent to the client. PHP is a popular server-side language that can be deployed on almost every operating system and platform.
The above is the detailed content of How to use the PHP Is_Numeric() function. For more information, please follow other related articles on the PHP Chinese website!