php函數: call_user_func()和call_user_func_array() 使用詳解

來源:互聯網
上載者:User

標籤:color   允許   使用方法   顯示   詳解   function   pre   入參   call   

call_user_func 該函數允許直接調用自己寫的函數,可以直接傳入一些參數。

使用方法1:給自己寫的函數傳入參數,一個特別的調用函數的方法。

 1 <?php 2  3 funciotn test1($a,$b){ 4       echo $a; 5       echo $b; 6 } 7 8 call_user_func(‘test1‘,"11","22"); 9 call_user_func(‘test1‘,"33","44");
//輸出結果 11 22 33 4410 ?>

使用方法2:調用類內建函式的時候用array

class a {    function b($c){        echo "$c";    }}call_user_func(array("a","b"),"111");//顯示111

call_user_func_array()的使用方法

使用方法1:call_user_func_array(): 用數組存放參數

    function b($c,$d){        echo $c;        echo $d;    }call_user_func_array(‘a‘,array("11","22"));
//輸出結果1122

使用方法2:call_user_func_array()  調用類內建函式

class a {    function bc($b,$c){        $bc=$b+$c;        echo $bc;    }}call_user_func_array(array("a","bc"),array("11","22"));//輸出結果 33

 

php函數: call_user_func()和call_user_func_array() 使用詳解

聯繫我們

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