Recommended Manual: php complete self-study manual
##php Commonly used functions for judging variables include gettype(), is_array(), is_bool(), is_float(), is_integer(), is_null(), is_numeric(), is_object(), is_resource(), is_scalar() and is_string() .
The gettype() function returns the type of the variable, such as "boolean", "integer", "double" (the float type will return "double" instead of "float"), "string", "array" ", "object", "resource", "NULL" and "unknown type" and other values indicate the variable type, such as:$var = "coding"; echo gettype($var);//string
$var1=321; var_dump(is_numeric($var1));//bool(true) $var2="123"; var_dump(is_numeric($var2));//bool(true)
1.settype($var,type) function conversion
$var='124das.21321'; settype($var,'int');//第二个参数指定转换类型,可以是int、float、bool、string、array和object var_dump($var);//int 124
2. Target type specified conversion
(int)$var;//括号内指定转换类型,可以是int、float、bool、string、array和object
3. Three specific type function conversion
intval($var) , floatval($var) and strval($var)$var = '121.212sdsa'; var_dump(floatval($var)); // float 121.212
Recommended related articles: 1.
How does PHP use the gettype() function to determine the type of a variable? 2.
How does php determine the file type 3.
php implementation to determine client type
Related video recommendations: 1.
Dugu Jiujian (4)_PHP video tutorial
The above is the detailed content of PHP determines variable type. For more information, please follow other related articles on the PHP Chinese website!