<address id="ousso"></address>
<form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
  1. php語言

    PHP學習10個基礎知識總結

    時間:2025-03-22 11:24:18 php語言 我要投稿
    • 相關推薦

    PHP學習10個基礎知識總結

      PHP學習過程中,必須要掌握基礎的知識點,以下是小編為大家搜索整理的PHP學習10個基礎知識總結,希望能給大家帶來幫助!更多精彩內容請及時關注我們應屆畢業生考試網!

    PHP學習10個基礎知識總結

      PHP10個小基礎知識總結1,在HTML嵌入PHP腳本有三種辦法:

    以下為引用的內容:
    <script language="PHP">
    //嵌入方式一
    echo("test");
    </script>
    <?
    //嵌入方式二
    echo "<br>test2";
    ?>
    <?PHP
    //嵌入方式三
    echo "<br>test3";
    ?>

      還有一種嵌入方式,即使用和ASP相同的標記,但要修改PHP.ini 相關配置,不推薦使用。

      2,PHP注釋分單行和多行注釋,和Java注釋方式相同。

    以下為引用的內容:
    <?
    //這里是單行注釋
    echo "test";
    /*
    這里是多行注釋!可以寫很多行注釋內容
    */
    ?>

      注意不要有嵌套注釋,如/*aaaa/*asdfa*/asdfasdfas*/,這樣的注釋會出現問題。

      3,PHP主要的數據類型有5種:

      integer,double,string,array,object。

      4,函數內調用函數外部變量,需要先用global進行聲明,否則無法訪問,這是PHP與其他程序語言的一個區別。事例代碼:

    以下為引用的內容:

    <?
    $a=1;
    function test(){
    echo $a;
    }
    test(); //這里將不能輸出結果“1”。
    function test2(){
    global $a;
    echo $a;
    }
    test2(); //這樣可以輸出結果“1”。
    ?>

      注意:PHP可以在函數內部聲明靜態變量。用途同C語言中。

      5,變量的變量,變量的函數

    以下為引用的內容:

    <?
    //變量的變量
    $a="hello";
    $$a="world";
    echo "$a $hello"; //將輸出"hello world"
    echo "$a ${$a}"; //同樣將輸出"hello world"
    ?>
    <?
    //變量的函數
    function func_1(){
    print("test");
    }
    function fun($callback){
    $callback();
    }
    fun("func_1"); //這樣將輸出"test"
    ?>

      6,PHP同時支持標量數組和關聯數組,可以使用list()和array()來創建數組,數組下標從0開始。如:

    以下為引用的內容:
    <?
    $a[0]="abc";
    $a[1]="def";
    $b["foo"]=13;
    $a[]="hello"; //$a[2]="hello"
    $a[]="world"; //$a[3]="world"
    $name[]="jill"; //$name[0]="jill"
    $name[]="jack"; //$name[1]="jack"
    ?>

      7,關聯參數傳遞(&的使用),兩種方法。例:

    以下為引用的內容:

    <?
    //方法一:
    function foo(&$bar){
    $bar.=" and something extra";
    }
    $str="This is a String,";
    foo($str);
    echo $str; //output:This is a String, and something extra
    echo "<br>";
    //方法二:
    function foo1($bar){
    $bar.=" and something extra";
    }
    $str="This is a String,";
    foo1($str);
    echo $str; //output:This is a String,
    echo "<br>";
    foo1(&$str);
    echo $str; //output:This is a String, and something extra
    ?>

      8,函數默認值。PHP中函數支持設定默認值,與C++風格相同。

    以下為引用的內容:
    <?
    function makecoffee($type="coffee"){
    echo "making a cup of $type.n";
    }
    echo makecoffee(); //"making a cup of coffee"
    echo makecoffee("espresso"); //"making a cup of espresso"
    /*
    注意:當使用參數默認值時所有有默認值的參數應該在無默認值的參數的后邊定義。否則,程序將不會按照所想的工作。
    */
    function test($type="test",$ff){ //錯誤示例
    return $type.$ff;
    }

      9,PHP的幾個特殊符號意義。

      $ 變量

      & 變量的地址(加在變量前)

      @ 不顯示錯誤信息(加在變量前)

      -> 類的方法或者屬性

      => 數組的元素值

      ?: 三元運算子

      10,include()語句與require()語句

      如果要根據條件或循環包含文件,需要使用include().

      require()語句只是被簡單的包含一次,任何的條件語句或循環等對其無效。

      由于include()是一個特殊的語句結構,因此若語句在一個語句塊中,則必須把他包含在一個語句塊中。

    以下為引用的內容:
    <?
    //下面為錯誤語句
    if($condition)
    include($file);
    else
    include($other);
    //下面為正確語句
    if($condition){
    include($file);
    }else
    {
    include($other);
    }
    ?>

     

    【PHP學習10個基礎知識總結】相關文章:

    php基礎知識學習筆記08-15

    php學習筆記:基礎知識01-16

    php學習筆記之基礎知識07-06

    學習php前要掌握的基礎知識04-17

    學習php前需要掌握的基礎知識05-30

    php基礎知識02-27

    PHP學習入門的一些基礎知識05-23

    新手PHP基礎知識04-05

    php語言基礎知識06-15

    <address id="ousso"></address>
    <form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
    1. 日日做夜狠狠爱欧美黑人