Maison  >  Article  >  développement back-end  >  php中call_user_func_array函数的用法举例

php中call_user_func_array函数的用法举例

WBOY
WBOYoriginal
2016-07-25 08:59:021108parcourir
  1. function test($a, $b)
  2. {
  3. echo '测试一:'.$a.$b;
  4. }
  5. //调用test方法,array("asp", 'php')对应相应的参数
  6. call_user_func_array('test', array("asp", 'php'));
  7. ?>
复制代码

二、通过类调用类中的方法

  1. class test2{
  2. function phpSay($a, $b)
  3. {
  4. echo '测试二:'.$a.$b;
  5. }
  6. }
  7. $o = new test2();
  8. //相当于:$o->phpSay('php','你好');
  9. call_user_func_array(array(&$o, 'phpSay'), array('php','你好'));
  10. ?>
复制代码


Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn