Home  >  Article  >  Backend Development  >  PHP judgment variable type implementation code_PHP tutorial

PHP judgment variable type implementation code_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:43:15716browse

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); //Return 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, indicating that $arr is an array
is_array($s); //Returns FALSE, Indicates 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);
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/320751.htmlTechArticlePHP includes several functions to determine the type of variables, such as: gettype(), is_array(), is_float() , is_int(), is_object() and is_string(). Copy the code The code is as follows: ?php $s = "th...
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