Home >Backend Development >PHP Tutorial >A brief discussion on the example code of the data type judgment function of variables in PHP
The following editor will bring you a brief discussion of the data type judgment function of variables in PHP. The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let’s follow the editor and take a look.
In php, we can print out the type and value of variables through var_dump(). At the same time, we can determine the type of variables through some functions. If you just want to get the data type of a variable, you can use the gettype() function. gettype($t) returns a string of the data type of $t. If $t does not belong to the 8 basic variable types in PHP, it returns "unknown type". We can also directly determine whether it is a type type function through the is_type series function. If so, it will return true, not false.
For example:
is_bool() Whether it is a Boolean type
is_int() Whether it is an integer type
is_float () Whether it is a floating point type
is_string() Whether it is a string type
is_array() Whether it is an array type
is_object() Whether it is an object type
is_resource() Whether it is a resource type
is_null() Whether it is empty
is_scalar() Whether it is a scalar type, that is, an integer floating point Boolean type or a string type.
is_numeric() Whether it is any type of number or numeric string
is_callable() Whether it is a valid function name
The above is a brief discussion of the data type judgment function example code of variables in PHP. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!