Most variable functions are used to test the type of a function. PHP has two common functions: gettype () and settype (). These two functions have the following function prototype, through which you can obtain the parameters to be passed and the returned
Most variable functions are used to test the type of a function. PHP has two common functions: gettype () and settype (). These two functions have the following function prototype, through which you can obtain the parameters to be passed and the returned results:
String gettype (mixed var );
Bool settype (mixed var, string type );
To use the gettype () function, you must first pass a variable to it. It determines the type of the variable and returns a string containing the type name: bool, int, double (for float type), string, array, object, and resource. If the variable type is not one of the standard types, the function returns "unknow type (unknown type )".
To use the settype () function, you must first pass a variable of the type to be changed, and a string containing a type in the above type list. You can use these functions as follows:
$ A = 100;
Echo gettype ($ ).'
';
Settype ($ a, 'double ');
Echo gettype ($ ).'
';
?>
The code above indicates that $ a is an integer when the gettype () function is called for the first time. After the settype () function is called, it becomes a double-precision type. The running result is as follows.
PHP also provides some specific types of test functions. Each function uses a variable as its parameter and returns true or false. These functions are as follows:
1. is_array (): Check whether the variable is an array.
2. is_double (): is_float (): is_real () (all functions are the same): Check whether the variable is a floating point number.
3. is_long (): is_int (): is_integer () (all functions are the same): Check whether the variable is an integer.
4. is_string (): Check whether the variable is a string.
5. is_bool (): Check whether the variable is a Boolean value.
6. is_object (): Check whether the variable is an object.
7. is_resource (): Check whether the variable is a resource.
8. is_null (): Check whether the variable is Null.
9. is_scalar (): checks whether the variable is a scalar, that is, an integer, Boolean value, string, or floating point number.
10. is_numeric (): checks whether the variable is a numeric or numeric string of any type.
11. is_callable (): Check whether the variable is a valid function name.