Home  >  Article  >  Backend Development  >  Variable type PHP judgment variable type implementation code

Variable type PHP judgment variable type implementation code

WBOY
WBOYOriginal
2016-07-29 08:41:041277browse

PHP includes several functions that can determine the type of variables, such as: gettype(), is_array(), is_float(), is_int(), is_object() and is_string().

Copy code The code is as follows:


$s = "this is a string";
$i = 9;
$arr = array(2,4,6);
is_string ($s); //Returns TRUE, indicating that $s is a string variable
is_string($i); //Returns FALSE, indicating that $i is not a string variable
is_array($arr); //Returns TRUE, Indicates that $arr is an array
is_array($s); //returns FALSE, indicating that $s is not an array
$str = "this is a string";
$int = 9;
$bool = FALSE;
echo " The type of $str is: ".gettype($str);
echo "
";
echo "
";
echo "The type of $int is: ".gettype($ int);
echo "
";
echo "
";
echo "The type of $bool is:".gettype($bool);
?>

The above introduces the implementation code of variable type in PHP to determine variable type, including the content of variable type. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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