PHP 物件型別的判斷

2021-09-21 13:24:47 字數 620 閱讀 9395

gettype描述

string gettype ( mixed $var )

返回 php 變數的型別 var.

warning

不要使用 gettype() 來測試某種型別,因為其返回的字串在未來的版本中可能需要改變。此外,由於包含了字串的比較,它的執行也是較慢的。

使用 is_* 函式代替。

返回的字串的可能值為:

「boolean」(從 php 4 起)

「integer」

「double」(由於歷史原因,如果是 float 則返回「double」,而不是「float」)

「string」

「array」

「object」

「resource」(從 php 4 起)

「null」(從 php 4 起)

「user function」(只用於 php 3,現已停用)

「unknown type」

對於 php 4,你應該使用 function_exists() 和 method_exists() 取代先前將 gettype() 作用於函式的用法。

php 型別判斷

學習筆記 判斷陣列 colors array red blue green if is array colors 雙精度數判斷 temperature 15.23 if is double temperature 整數判斷 pagecount 2234 if is integer pagecount...

PHP型別判斷

定義 型別判斷是系統通過指定函式來確定資料類別,給定判定結果為布林值,是對應型別返回true,不是對應型別返回false 通過系統函式判定資料型別 函式的格式很好記,使用is 開頭,後面跟對應資料型別,可以通過操作手冊is 進行搜尋查詢 php操作手冊.chm 索引 輸入is 以下講幾個常用的判定函...

PHP型別判斷

1 常規型別判斷 isset 變數是否已經宣告 empty 變數是否為空,等於說 0 0 null false array var var 未定義 以及沒有任何屬性的物件都將被認為是空的,如果 var 為空,則返回 true。defined 常量是否已經定義 define is numeric mi...