Common methods for determining variable types in php
Source: Internet
Author: User
Common php variable judgment functions include gettype (), is_array (), is_bool (), is_float (), is_integer (), is_null (), is_numeric (), is_object (), is_resource (), is_scalar (), and is_string (). now let's take a look at the specific usage.
Gettype ()
Gettype returns the following values based on the parameter type.
"Boolean" (from PHP 4)
"Integer"
"Double" (if float is used, "double" is returned instead of "float ")
"String"
"Array"
"Object"
"Resource" (from PHP 4)
"NULL" (from PHP 4)
"Unknown type"
For example:
Gettype ('1'); returns string
Gettype (1); returns integer
Is_array ()
Is_array () is relatively simple to use
Returns true if the parameter is an array; otherwise, returns false.
The usage and return values of other functions are similar to those of is_array ().
Here, we need to note that is_numeric () is used to determine whether the variable is a number or a number string.
Returns true if the is_numeric () parameter is a numeric or numeric string. otherwise, returns false.
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