In PHP because variables do not need to be defined in advance, we have a lot of time for the PHP variable type is cheek paste, but PHP gives us the GetType () function to get the variable type, he can judge all the variable types in PHP.
Detecting variable types
GetType ($var)
This function returns the type of the variable. For example, "string", "Integer", "Boolean", "floating-point value", and so on. This function is commonly used to verify that a variable is the type you expect before inserting a variable into a strictly typed database field.
The code is as follows |
Copy Code |
Returns string $var = "Hello"; Echo GetType ($var); Returns double $var = 1000.56; Echo GetType ($var); ?> |
Warning
Do not use GetType () to test for a type, because the string it returns may need to be changed in a future release. In addition, it is slower to run because it contains a comparison of strings.
Use the is_* function instead.
Check for valid variables
Isset is used to determine the existence of a variable, if it is true otherwise return false, this variable is useful to us, we can be used to determine such as a get post, such as whether the variable is in the OH.
Isset instance "
The code is as follows |
Copy Code |
$a = "Test"; $b = "Anothertest"; echo isset ($a)? ' True ': ' false '; The output is: true |
Example 2
The code is as follows |
Copy Code |
Returns True $var = "Yes"; echo isset ($var)? "True": "false"; Returns false echo isset ($test)? "True": "false"; ?> |
The above is two super simple PHP function Isset () and GetType () function is not difficult, there is need to know the friend can refer to.
http://www.bkjia.com/PHPjc/629174.html www.bkjia.com true http://www.bkjia.com/PHPjc/629174.html techarticle In PHP because variables do not need to be defined in advance, we have a lot of time for PHP variable type is cheek paste, but PHP provides us with the GetType () function to get the variable type, he can judge ...