php語言基礎學習筆記

來源:互聯網
上載者:User

花了一個小時複習了一下很多年沒有碰了的php,mark一下,高二時學的。

1. 代碼嵌在<?php  ?>內

2.輸出函數echo,相當於js中的document.write

3.可以在列印雙引號時用單引號或者在列印雙引號時使用單引號。

   echo 'She said,"how you are?"';

   echo "she said,'how you are?'";

4.在同樣的引號或者列印需要轉義的符號可以使用\,echo 'I \'m just ducky.'; echo "she said,\"How are you?\"";

5.注釋推薦使用shell風格,#this is a comment

6.變數同c,前面有$.

    echo $money;

    echo "hello,$money";

7.連接字串 $aa = "sdfs";$bb = "fsdfs"; $cc = $aa.$bb;

   $cc = $cc."fsdfs";

8.關於數字

    $n = 2.13;

   $n = round($n);   //3  四捨五入

   $n = 3.13141;

   $n = round($n,3);   //3.131保留位元的四捨五入

  $n = number_format($n);   //加分隔字元

   $n  = number_format($n,4);//設定位元的加分割符

9.常量

  define('NAME','VALUE');

  echo NAME;

10.get用於發起資料請求,post使用者單向發送資料

11.$_REQUEST為超全域變數,為$_POST和$_GET的集合

12.isset()函數用於確定一個變數是否有值

13.empty()函數用於確定一個變數是否為空白值

14.檢驗是否為數字使用is_numeric函數

15.數組

    $band[] = "sdfs";

   $band[] = "sdfs";

   $ band[] = "huhu";

   $state = array(key1 => value1,key2 => value2.......);

  索引值對應     echo $state[key1];

  foreach($array as $key =>$value){

}

   二維數組

  $array2 = (key1=>array1,.......);

16.排序

    sort按值排序,重設健值關係

    asort按值排序,維持索引值關係

    ksort按鍵排序

   rsort,arsort,krsort反向排序

17.迴圈判斷略

18.包含檔案

    include(url);

    require(url);  //可包含多次

    include_once(url);

     require(url);  //只能包含一次

19.處理html表單

   if($isset($_POST['submitted'])){

  }

else{

}

20.$page_title設定標題

21.設定粘性表單

   <input type="text" name="city" size="20" value="<?php echo $city;>" />

22.函數參考js的函數

   注意可以返回一個數組

    例如return array($avariable1,$avariable2);

    可以設定預設參數

    function greet($name,$msg = "hello"){

}

23.要想使函數內的變數可以被外部使用可以global

    function xxx(){

     global $fsdf;

聯繫我們

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