Example of call_user_func_array callback function in PHP: calluserfuncarray

Source: Internet
Author: User

Example of call_user_func_array callback function in PHP: calluserfuncarray

Call_user_func_array

call_user_func_array-Call the callback function and use an array parameter as the callback function parameter.

mixed call_user_func_array ( callable $callback , array $param_arr )

Call the first parameter as the callback function, and pass in the parameter array as the parameter (param_arr) of the callback function.

Example:

function foobar($arg, $arg2) {  echo __FUNCTION__, " got $arg and $arg2\n";}class foo {  function bar($arg, $arg2) {    echo __METHOD__, " got $arg and $arg2\n";  }}// Call the foobar() function with 2 argumentscall_user_func_array("foobar", array("one", "two"));dump("<br/>");// Call the $foo->bar() method with 2 arguments$foo = new foo;call_user_func_array(array($foo, "bar"), array("three", "four"));

Output result:

foobar got one and twofoo::bar got three and four

Summary

The above is all the content of this article. I hope the content of this article will be helpful for everyone to learn or use PHP. If you have any questions, please leave a message.

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.