學習函數知識

來源:互聯網
上載者:User

標籤:function   知識   關鍵詞   

2016.12.19.星期一


    一、

      1.全域變數:定義在函數外面的變數

        2.局部變數:定義在函數內部,生命週期函數運行完畢,也就結束了。

     二、

        $a=2;

        $b=7;

        function add(){

                使用關鍵詞global引入

        global $a;

        global $b;

        echo $a + $b;

            }

                add();

      三、       

           $a=10;

         $b=20;

         function abb(){

         超全域變數$GLOBALS[‘變數名‘]

         echo $GLOBALS[‘a‘]+$GLOBALS[‘b‘];


            }

         abb();

      四、       

            function jingtai(){

            靜態變數:只有在初始化的時候進行一次賦值。

        static $c = 0;

        $c++;

        echo $c;

        if(1 == $c){

echo "HELLO";

        }

            }

            jingtai();

            jingtai();

            jingtai();

            jingtai();

      五、

   一個隨便輸入資料,如果是奇數就輸出,偶數就輸出提示“您輸入的是偶數”。

            function oneTwo(&$num){

    if( 0 != $num % 2  ){

echo $num;

    }else{

echo "您輸入的是偶數";

    }

        }

            $a = 2;

            oneTwo($a);

       六、輸出100之內的所有的奇數。

            function guolv2($num){

return ($num %2 == 0)?1:0;

        }

        function guolv1($num){

return ($num %2 == 1)?1:0;

        }

        function tichu($a,$b){

for($i = 1; $i <= $a; $i ++){

if($b($i)){

continue;

}

echo $i."<br>";

    }

        }

        tichu(100,‘guolv2‘);

    



        



學習函數知識

聯繫我們

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