首页 > 代码库 > func_get_args call_user_func_array

func_get_args call_user_func_array

 

<?php
//call_user_func_array.php
   function test($arg1,$arg2)
   {
    $t_args = func_get_args();
    $t_result = call_user_func_array( ‘gpc_get‘, $t_args );
    var_dump($t_result);
   }

    function gpc_get($args)
    {
        echo ‘in gpc_get function:<br>‘;
        var_dump($args);
        echo ‘<hr>‘;
        if(!is_array($args))
        {
            return ‘gpc_get~‘ . $args ;
        }
        else
        {
            $ret=array();
            $len=count($args);
            for($i=0;$i<$len;$i++)
            {
                $ret[]= ‘gpc_get~‘ . $args[$i] ;
            }
            return $ret;
        }
    }

    test(‘hello‘,‘world‘);
    test(array(‘aaaaa‘,‘bbbbb‘,‘ccccc‘,‘ddddd‘),‘world‘);

/*
in gpc_get function:
string ‘hello‘ (length=5)

string ‘gpc_get~hello‘ (length=13)



in gpc_get function:
array (size=4)
  0 => string ‘aaaaa‘ (length=5)
  1 => string ‘bbbbb‘ (length=5)
  2 => string ‘ccccc‘ (length=5)
  3 => string ‘ddddd‘ (length=5)

array (size=4)
  0 => string ‘gpc_get~aaaaa‘ (length=13)
  1 => string ‘gpc_get~bbbbb‘ (length=13)
  2 => string ‘gpc_get~ccccc‘ (length=13)
  3 => string ‘gpc_get~ddddd‘ (length=13)
*/
?>

 

func_get_args call_user_func_array