PHP函數初識(1)

來源:互聯網
上載者:User

標籤:function   private   區分大小寫   關鍵字   public   

                                                        函數

php函數的定義方式:

修飾符  function 函數名(參數1,參數2...){

    執行體.

}

修飾符: 

public :公有的.(預設許可權)

private : 私人的.  

protected:受保護的. 1:必須要使用關鍵字‘function‘ ;2:函數名可以是字母或底線開頭.3:在大括弧中編寫函數體.判斷函數是否存在:    function_exists(‘函數名‘);  注意點:函數調用不區分大小寫。  例如:  Name()=========》name();  變數可以按引用傳遞,在參數前加&;  $ceshi=10;  function test4(&$a){$a=80;}test4($ceshi);echo $ceshi;//值被改變
 <?php$ceshi = 10;//無參無傳回值function test(){echo "Hello PHP";}test();echo "<br/>";echo "<br/>";//無參有傳回值function test1(){$ceshi2 = 50;return $ceshi2; }$c  =test1();echo $c ;echo "<br/>";echo "<br/>";//有參無傳回值function test2($ceshi){$ceshi = 30;}test2($ceshi);echo $ceshi;//值不會被改變echo "<br/>";echo "<br/>";//有參有傳回值function test3($ceshi){$num = $ceshi*15;return $num;} $num = test3($ceshi);echo $num;//可變函數://通過變數的值來自己調用函數.$func = ‘test‘;$func();$func = ‘test1‘;$func();$func = ‘test2‘;$func($ceshi);$func = ‘test3‘;$func($ceshi);


本文出自 “12897581” 部落格,請務必保留此出處http://12907581.blog.51cto.com/12897581/1937375

PHP函數初識(1)

聯繫我們

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