Home >Backend Development >PHP Tutorial >Usage example of call_user_func_array function in php

Usage example of call_user_func_array function in php

WBOY
WBOYOriginal
2016-07-25 08:59:021153browse
  1. function test($a, $b)
  2. {
  3. echo 'Test 1:'.$a.$b;
  4. }
  5. //Call the test method, array("asp", 'php') corresponds to the corresponding parameters
  6. call_user_func_array('test', array("asp", 'php'));
  7. ?>
Copy the code

2. Call the method in the class through the class

  1. class test2{
  2. function phpSay($a, $b)
  3. {
  4. echo 'Test 2:'.$a.$b;
  5. }
  6. }
  7. $o = new test2 ();
  8. //Equivalent to: $o->phpSay('php','Hello');
  9. call_user_func_array(array(&$o, 'phpSay'), array('php','Hello' ));
  10. ?>
Copy code


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