Demonstration of call_user_func_array () function usage in PHP _ php entry _ script house

Source: Internet
Author: User
Today, I read a piece of code and used many call_user_func_array () functions. At the beginning, they were very confused. Later I found through the manual that the call_user_func_array () function is still very useful, so the call_user_func_array () function usage in PHP is described in a simple code example.

Today, I read a piece of code and used many call_user_func_array () functions. At the beginning, they were very confused. Later I found through the manual that the call_user_func_array () function is still very useful, so the call_user_func_array () function usage in PHP is described in a simple code example.

Call_user_func_array
(PHP 4> = 4.0.4, PHP 5)

Call_user_func_array -- Call a user function given with an array of parameters
Description
Mixed call_user_func_array (callback function, array param_arr)

Call a user defined function given by function, with the parameters in param_arr. For example:

Example 1. call_user_func_array () example
The Code is as follows:
Function debug ($ var, $ val)
{
Echo "*** DEBUGGING \ nVARIABLE: $ var \ nVALUE :";
If (is_array ($ val) | is_object ($ val) | is_resource ($ val )){
Print_r ($ val );
} Else {
Echo "\ n $ val \ n ";
}
Echo "*** \ n ";
}

$ C = mysql_connect ();
$ Host = $ _ SERVER ["SERVER_NAME"];

Call_user_func_array ('debug', array ("host", $ host ));
Call_user_func_array ('debug', array ("c", $ c ));
Call_user_func_array ('debug', array ("_ POST", $ _ POST ));
?>

The Code is as follows:
Function test ($ str ){
Echo $ str;
}

Call_user_func_array ("test", "NO.1 www.chhua.com"); // output "NO.1 www.chhua.com"
// Parameter description "the first parameter is the function name and the second parameter.
Class testClass {
Public function write ($ str ){
Echo $ str;
}
}
Call_user_func_array (array (testClass, write), "NO.1 www.chhua.com"); // when calling with a class, use array (), array (Class Name, method name)
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.