Home  >  Article  >  Backend Development  >  Usage of call_user_func_array callback function in PHP

Usage of call_user_func_array callback function in PHP

墨辰丷
墨辰丷Original
2018-05-30 14:26:511741browse

This article mainly introduces the usage of the call_user_func_array callback function in PHP. The article gives detailed example code. I believe it is helpful for everyone's understanding and learning. Friends in need can refer to it. Below Let’s learn together.

call_user_func_array

call_user_func_array — Call the callback function and pass an array parameter as the parameter of the callback function

mixed call_user_func_array ( callable $callback , array $param_arr )

Call the first parameter as the callback function (callback), and pass in the parameter array (param_arr) as the parameter 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 arguments
call_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 two

foo::bar got three and four

The above is the entire content of this article, I hope it will be helpful to everyone's study.


Related recommendations:

PHP implements recursive deletion of a value in a multi-dimensional array

phpHow to accurately determine the file type without using the extension

PHP uses the finfo_file() function to implement the method of detecting the type of uploaded images

The above is the detailed content of Usage of call_user_func_array callback function in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn