【函数功能】
该函数返回指定变量的数据类型。
【函数语法】
gettype ($var)
【参数说明】
$var:参数变量。
【演示程序】
<?php
/**
* gettype ($var)
* **/
$var = mysql_connect("localhost","root","");
echo (gettype($var))."<br>";
$var = 123;
echo(gettype($var))."<br>";
$var = "php1234";
echo(gettype($var))."<br>";
$var = "1234";
echo(gettype($var))."<br>";
$var = array("php1234.cn");
echo(gettype($var))."<br>";
$var = "";
echo(gettype($var))."<br>";
$var1;
echo(gettype($var1))."<br>";
?>
【输出结果】
resource
integer
string
string
array
string
NULL
【特别注意】
1.该函数返回变量类型。
2.返回的变量类型有如下:
“boolean”(从 PHP 4 起)
“integer”
“double”(由于历史原因,如果是 float 则返回“double”,而不是“float”)
“string”
“array”
“object”
“resource”(从 PHP 4 起)
“NULL”(从 PHP 4 起)
“user function”(只用于 PHP 3,现已停用)
“unknown type”
3.PHP版本:PHP3+。
【原版定义】
/**
* Get the type of a variable
* @link http://www.php.net/manual/en/function.gettype.php
* @param var mixed <p>
* The variable being type checked.
* </p>
* @return string Possible values for the returned string are:
* "boolean"
* "integer"
* "double" (for historical reasons "double" is
* returned in case of a float, and not simply
* "float")
* "string"
* "array"
* "object"
* "resource"
* "NULL"
* "unknown type"
*/
转载请注明出处:php1234.cn ,原文地址:http://www.php1234.cn/a/functions/2017/0612/232.html