The method to check the variable type in PHP is very simple. Use the gettype() function to return the current variable type. Now I will introduce to you in detail how to use the gettype function to check the variable type. Friends who need to know more can refer to.
string gettype ( mixed $var ) returns the type of PHP variable var.
Example
The code is as follows
|
Copy code
|
||||||||
function get_type($var) { If(is_object($var))
If(is_null($var)) return 'array'; If(is_int($var))return 'integer'; If(is_bool($var))return 'boolean'; If(is_float($var))return 'float'; If(is_resource($var))return 'resource'; //throw new NotImplementedException();Return 'unknown'; }?>
Officially said: Do not use gettype() to test a certain type, because the string it returns may need to change in future versions. Additionally, due to the inclusion of Without string comparison, its operation is also slower. Use is_* functions instead.
Related labels:
source:php.cn
Previous article:PHP prompt Notice: Undefined index error solution_PHP tutorial
Next article:Convert between PHP timestamp and date_PHP Tutorial
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Issues
Group MySQL results by ID for looping over
I have a table with flight data in mysql. I'm writing a php code that will group and displ...
From 2024-04-06 17:27:56
0
1
406
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
|