Home >Backend Development >PHP Tutorial >Variable type PHP judgment variable type implementation code
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.