PHP gettype() 函式
示例
返回不同變數的型別
<?php
$a = 3;
echo gettype($a) . "<br>";
$b = 3.2;
echo gettype($b) . "<br>";
$c = "Hello";
echo gettype($c) . "<br>";
$d = array();
echo gettype($d) . "<br>";
$e = array("red", "green", "blue");
echo gettype($e) . "<br>";
$f = NULL;
echo gettype($f) . "<br>";
$g = false;
echo gettype($g) . "<br>";
?>
自己動手試一試 »
定義和用法
gettype() 函式返回變數的型別。
語法
gettype(variable);
引數值
引數 | 描述 |
---|---|
變數 | 必需。指定要檢查的變數 |
技術詳情
返回值 | 型別字串。可以是以下值之一:“boolean”、“integer”、“double”、“string”、“array”、“object”、“resource”、“NULL”、“unknown type” |
---|---|
返回型別 | 字串 |
PHP 版本 | 4.0+ |
PHP 更新日誌 | PHP 7.2:已關閉的資源現在返回“resource (closed)”。在此之前,返回值是“unknown type”。 |
❮ PHP 變數處理參考