An example of usage of php's call_user_func_array() function

WBOY
Release: 2016-07-25 08:52:07
Original
1189 people have browsed it
  1. function debug($var, $val)

  2. {
  3. echo "***DEBUGGINGnVARIABLE: $varnVALUE:";
  4. if (is_array($val) || is_object ($val) || is_resource($val)) {
  5. print_r($val);
  6. } else {
  7. echo "n$valn";
  8. }
  9. echo "***n";
  10. }

  11. $c = mysql_connect();

  12. $host = $_SERVER["SERVER_NAME"];

  13. call_user_func_array('debug', array("host", $host)) ;

  14. call_user_func_array('debug', array("c", $c));
  15. call_user_func_array('debug', array("_POST", $_POST));
  16. ?>

Copy code

  1. function test($str) {
  2. echo $str;
  3. }

  4. call_user_func_array("test" ,"NO.1 www.chhua.com");//Output "NO.1 www.chhua.com"

  5. //Parameter description "The first parameter is the function name, the second is the parameter
  6. class testClass {
  7. public function write($str){
  8. echo $str;
  9. }
  10. }
  11. call_user_func_array(array(testClass,write),"NO.1 www.chhua.com");//When calling with a class, use array (), array (class name, method name)
  12. ?>

Copy code


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 admin@php.cn
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!