call_user_func函数

<?php
function funa($b,$c)
{
    echo $b;
    echo $c;
}
call_user_func('funa', "111","222");
call_user_func('funa', "333","444");
//显示 111 222 333 444
//大家有没有发现,这个用法有点像javascript中的call方法,嘿嘿
?>
// 第二种是调用类内部的函数:
<?php
class a {
    function b()
    {
        $args = func_get_args();
        $num = func_num_args();
        print_r($args);
        echo $num;
    }
}
call_user_func(array("a", "b"),"111","222");
?>

<?php
function a($b, $c)
{
    echo $b;
    echo $c; 
}
call_user_func_array('a', array("111", "222"));
//显示 111 222
?>

//call_user_func_array函数也可以调用类内部的方法的:
<?php
Class ClassA
{
    function bc($b, $c) {
        $bc = $b + $c;
        echo $bc;
    }
}
call_user_func_array(array(‘ClassA','bc'), array(“111″, “222″));
//显示 333
?>

<?php
function otest1 ($a)
{
     echo( '一个参数' );
}

function otest2 ( $a, $b)
{
    echo( '二个参数' );
}

function otest3 ( $a ,$b,$c)
{
    echo( '三个啦' );
}

function otest (){
    $args = func_get_args();
    $num = func_num_args();
    call_user_func_array( 'otest'.$num, $args  );
}
otest("11");
otest("11","22");
otest("11","22","33");
?>
原文地址:https://www.cnblogs.com/luzai1989/p/5596284.html