函式名稱:gettype()
函式描述:gettype() 函式用於獲取變數的資料型別。
用法:gettype(變數)
引數:
- 變數:要獲取型別的變數。
返回值:返回變數的資料型別,以字串形式表示。
示例:
<?php
$var1 = "Hello World";
$var2 = 123;
$var3 = true;
$var4 = array(1, 2, 3);
echo gettype($var1); // 輸出: string
echo gettype($var2); // 輸出: integer
echo gettype($var3); // 輸出: boolean
echo gettype($var4); // 輸出: array
?>
注意事項:
- gettype() 函式不適用於常量,只適用於變數。
- 如果變數未定義或為 NULL,將返回字串 "NULL"。
- 如果變數為資源型別,將返回字串 "resource"。
- 如果變數為物件型別,將返回字串 "object"。
- 如果變數為陣列型別,將返回字串 "array"。
- 如果變數為布林型別,將返回字串 "boolean"。
- 如果變數為整數型別,將返回字串 "integer"。
- 如果變數為浮點數型別,將返回字串 "double"。
- 如果變數為字串型別,將返回字串 "string"。