Usage of call_user_func_array callback function in PHP

墨辰丷
Release: 2023-03-28 13:36:01
Original
1610 people have browsed it

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 )
Copy after login

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("
"); // Call the $foo->bar() method with 2 arguments $foo = new foo; call_user_func_array(array($foo, "bar"), array("three", "four"));
Copy after login

Output result:

foobar got one and two

foo::bar got three and four
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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 [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!