Home > Backend Development > PHP Problem > How to check variable type in php

How to check variable type in php

王林
Release: 2023-03-04 21:02:02
Original
4987 people have browsed it

How to check the variable type in php: You can use the gettype() function to get the type of the variable. The specific usage method is: [gettype(new stdclass())], which indicates whether it is an object type.

How to check variable type in php

#gettype() function is used to get the type of a variable.

(Recommended tutorial: php graphic tutorial)

Note: Do not use gettype() to test a certain type, because the string it returns will not be used in future versions may need to be changed. In addition, it runs slower due to the inclusion of string comparisons. Use the is_* functions instead.

Grammar:

string gettype ( mixed $var )
Copy after login

(Video tutorial recommendation: php video tutorial)

Example:

<?php
echo gettype(102) . PHP_EOL;
echo gettype(true) . PHP_EOL;
echo gettype(&#39; &#39;) . PHP_EOL;
echo gettype(null) . PHP_EOL;
echo gettype(array()) . PHP_EOL;
echo gettype(new stdclass());
?>
Copy after login

Output results :

integer
boolean
string
NULL
array
object
Copy after login

The above is the detailed content of How to check variable type in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template