search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

[PHP 手冊] -PHP 支援 8 種原始資料類型 – jashliao部落格

[PHP 手冊] –PHP 支援 8 種原始資料類型

 

資料來源: http://www.ithome.com/html/soft/72723.htm

code2html:http://tohtml.com/

 

四種標量類型:

  • boolean(布林型)
  • integer(整型)
  • float(浮點型,也稱作 double)
  • string(字串)

兩種複合類型:

  • array(陣列)
  • object(對象)

最後是兩種特殊類型:

  • resource(資源)
  • NULL(無類型)

為了確保代碼的易讀性,本手冊還介紹了一些偽類型:

  • mixed(混合類型)
  • number(數位類型)
  • callback(回調類型)

以及偽變數 $…

可能還會讀到一些關於”雙精度(double)”類型的參考。實際上 double 和 float 是相同的,由於一些歷史的原因,這兩個名稱同時存在。

變數的類型通常不是由程式師設定的,確切地說,是由 PHP 根據該變數使用的上下文在運行時決定的。

 

<html>
<head>
<metahttp-equiv="Content-Type"content="text/html; charset=utf-8">
<title>02_PHP變數型態title>
head>
<body>

header("Content-Type:text/html; charset=utf-8");
$a_bool=TRUE;// a boolean
$a_str="foo";// a string
$a_str2='foo';// a string
$an_int=12;// an integer
echogettype($a_bool);// prints out:  boolean
echo"
"
; echogettype($a_str);// prints out: string // If this is an integer, increment it by four if(is_int($an_int)){ $an_int+=4; } // If $bool is a string, print it out // (does not print out anything) if(is_string($a_bool)){ echo"String: $a_bool"; } ?> body> html>

 

 




熱門推薦

本文由 jashliaoeuwordpress 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦