PHP入門培訓教程 PHP 資料類型

來源:互聯網
上載者:User

標籤:double   字串   布爾   曆史   資源   

PHP入門培訓教程 PHP 資料類型

  PHP 支援八種原始類型(type),下面兄弟連PHP培訓小編來給大家列出:。

  四種標量類型:

  string(字串)

  integer(整型)

  float(浮點型,也作 double )

  boolean(布爾型)

  兩種複合類型:

  array(數組)

  object(對象)

  兩種特殊類型:

  resource(資源)

  NULL(空)

  查看變數類型

  通過 gettype() 函數可以方便的查看某個變數的類型:

  <?php$var_bool = TRUE;// a boolean$var_str = "foo"; // a string$var_int = 12; // anintegerecho gettype($var_bool); // 輸出 booleanechogettype($var_str); // 輸出 stringecho gettype($var_int);// 輸出 integer?>

  提示

  由於曆史原因,如果是 float 類型資料,gettype() 函數返回的是 double,而不是 float 。

  如果想查看某個運算式的值和類型,請使用用var_dump() 函數。

  判斷變數類型

  如果想通過判斷變數類型來確定下一步邏輯動作,不要使用gettype() ,而使用 is_type 系列函數:

  <?php$var_int = 12;// 如果 $var_int 是 int 類型,這進行加法if (is_int($var_int)) { $var_int = $var_int+4;}echo $var_int; // 輸出 16?>

 


PHP入門培訓教程 PHP 資料類型

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.