Parameter passing in call_user_func_array

Source: Internet
Author: User
Parameter passing in call_user_func_array
 

The following two lines are output:
Array (3) {[0] => string (3) "123" [1] => int (234) [2] => string (3) "fd "}
String (3) 123"

Why is the output of $ p not the entire array, but a string (3) "123 "? I read this manual:
Mixed call_user_func_array (callable $ callback, array $ param_arr)
Param_arr: The parameters to be passed to the callback, as an indexed array.
That is to say, the associated array will be passed.


Reply to discussion (solution)

For your code
Call_user_func_array ('B', $ p );
The actual execution is
B ('123', 123, 'cdg ')
That is, three parameters are passed to function B.

Function B ($ p) declares only one form parameter $ p.
So you can directly access var_dump ($ p) in the function; // 123

I have just read other examples and understood. Thank you, Xu

Function (){
$ P ['asdf '] = '000000 ';
$ P ['dfd '] = 234;
$ P ['hj3'] = 'cdg ';
Call_user_func_array ('B', array ($ p ));
}

Function B ($ p ){
$ P2 = func_get_args ();
Var_dump ($ p2 );
Var_dump ($ p );
}

A ();
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.