php手冊翻閱筆記(1)

來源:互聯網
上載者:User
php手冊閱讀筆記(1)

1. Language Reference | Basic Syntax

? ? php檔案尾部的結束標記(?>)最好省略,防止檔案尾部添加多餘的空格和斷行符號

? ? 可以使用/* */, //, #方式的注釋

?

2. 類型

? ? 支援四種標量:boolean、integer、float(與double相同)、string

? ? 支援兩種結構:array、object

? ? 支援三種特殊類型:resource、NULL、callable

?

? ? 類型沒必要設定,在運行期間PHP可以自行根據上下文推匯出來。

?

<%php$a_bool = TRUE;$a_str = "Str";$a_str2 = 'Str';$an_int = 12;echo get_type($a_bool);if (is_int($an_int)) {    echo "int";}

?

? ? boolean: TRUE/FALSE, (bool), 空數組也是FALSE

? ? integer:與C類似

? ? float:與C類似

? ? string:單引號,雙引號(變數可擴充),heredoc,nowdoc,heredoc中的變數展開,nowdoc中的不展開,heredoc是<<

? ? array:是有序map,可以作為數組、鏈表、雜湊表等使用。使用array()建立,其中可以放逗號分開的key=>value。

? ? ? ? ? ? ? ?key可以是整數,也可以是字串,字串中的內容為整數的,將被轉為整數;float轉為整數,boolean轉為整數,value可以是任意值。

? ? ? ? ? ? ? ?php5.4後,array()結構可以替換為[].

? ? ? ? ? ? ? ?php array的key中,可以既有整數又有字串,因為php不區分索引數組和關聯陣列。

? ? ? ? ? ? ? ?"key =>"可以省略,使用前面最大的整數key+1,key從0開始。

? ? ? ? ? ? ? ?給數群組成員賦值時key也可以省略:$arr[] = 24; 此時也是最大整數key+1

? ? ? ? ? ? ? unset刪除成員

? ? ? ? ? ? ? foreach迴圈:foreach($arr as $item) {$item...}

? ? object:通過new classname建立的一個class的執行個體。class中可以有function xxx()定義的method,object->xxx()訪問method。

?

3. 變數

? ? 使用$開頭,大小寫敏感

?

4. 常量

? ? define("name", "value");

? ? const HELLO = "hello";

?

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.