PHP commonly used to determine the function of variables are GetType (), Is_array (), Is_bool (), Is_float (), Is_integer (), Is_null (), Is_numeric (), Is_object (), Is_ Resource (), Is_scalar (), and is_string ().
Where the GetType () function returns the type of the variable, such as "Boolean", "Integer", "Double" (The Float type returns "Double" rather than "float"), "string", "array", "Object", " Resource "," NULL ", and" unknown type "are equivalent, indicating the type of the variable, as an example:
$var = "coding"; Echo GetType ($var);//string
The other function is to confirm for a variable type, return True or false, as an example:
$var 1=321;var_dump (Is_numeric ($var 1)),//bool (true) $var 2= "123"; Var_dump (Is_numeric ($var 2));//bool (True)
Note: Is_numeric () is used to determine if a variable is a numeric or numeric string
Attached: type conversion
If GetType () is used to get the variable type, then Settype () is obviously setting the variable type, which summarizes several types of conversion methods:
1.settype ($var, type) function conversion
$var = ' 124das.21321 '; Settype ($var, ' int ');//The second parameter specifies the type of conversion, which can be int, float, bool, string, array, and Objectvar_dump ($var); int 124
2. Target type Specifies conversion
(int) $var;//Specify the type of conversion in parentheses, which can be int, float, bool, string, array, and object
3. Three specific types of function conversions
Intval ($var), Floatval ($var) and Strval ($var)
$var = ' 121.212SDSA '; Var_dump (Floatval ($var)); Float 121.212