w3school的PHP教程提煉(一)PHP基礎

來源:互聯網
上載者:User
w3school的PHP教程提煉(一)PHP基礎

本筆記只提煉php需要注意的部分,關於運算子,簡單判斷等內容一概不寫。

1 字串

1.1 strlen()Function Compute字串長度

                  

1.2 strops()函數在字串內檢索字串或字元

                  

2 數組

2.1 數值數組 帶有數字ID鍵的數組

自動分配ID鍵:

                  

$names = array ( " a " , " b " , " c " );

人工分配ID鍵:

                  

$names [ 0 ] = " a " ; $names [ 1 ] = " b " ; $names [ 2 ] = " c " ;

使用ID鍵:

                  

2.2 關聯陣列 數組中的每個ID鍵關聯一個值

將值作為鍵分配:

                  

$ages = array ( " a " => 10 , " b " => 20 , " c " => 30 );

另一種方法:

                  

$ages [ " a " ] = " 10 " ; $ages [ " b " ] = " 20 " ; $ages [ " c " ] = " 30 " ;

使用ID鍵:

                  

2.3 多維陣列 包含一個或多個數組的數組(略)

3 迴圈

3.1 while

                  

" $i ++ ;} ?>

3.2 do...while

                  

" ;} while ( $i < 5 ); ?>

3.3 for

                  

" ;} ?>

3.4 foreach

foreach語句用於迴圈遍曆數組,每進行一次迴圈,當前數組元素的值就會被賦值給value變數(數組指標會逐一地移動)以此類推。

文法

                  

foreach ( array as value){ // ... }

樣本:輸出給定數組的值

                  

" ;} ?>

4 函數

4.1 傳遞參數

                  

" ;} echo " my name is " ;writeName( " Gang " , " Li " ); echo " my name is " writeName( " San " , " Zhang " ); ?>

4.2 傳回值

                  

5 表單處理

$_GET變數用於收集來自method="get"的表單的值。

$_POST變數用於收集來自method="post"的表單的值。

5.1 $_GET變數

form.php

                  

< form action ="welcome.php" method ="get" > Name: < input type ="text" name ="name" /> Age: < input type ="text" name ="age" /> < input type ="submit" />

welcome.php

                  

Welcome .< br /> You are years old !

5.2 $_POST變數

與$_GET不同之處在於:

$_POST沒有發送資訊量限制,而$_GET限制100字元

$_POST不在url處體現表單中的值,而$_GET傳遞的url可以加入收藏夾

5.3 $_REQUEST變數

$_REQUEST變數可用來取得通過get和post方法發送到表單資料的結果

  • 聯繫我們

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