Call_user_func and call_user_func_array functions are parsed. Today, by accident, I again saw the call_user_func_array () function in php in the official CodeIgniter document. I also encountered this function in the discuz Forum code last year, today, by chance on the Internet, I again saw the call_user_func_array () function in php in the official CodeIgniter document. I also encountered this function in the discuz Forum code last year, I checked the usage of this function on the Internet today. I would like to share with you the usage of this call_user_func_array and call_user_func functions. In addition, I will provide the usage instructions for func_get_args () and func_num_args () functions.
Call_user_func is used when a function needs to be called dynamically. this function has two usage methods, which are described below:
(1) call the lonely function:
(2) call internal functions of the class:
In the preceding example, the result is as follows:
Array
(
[0] = & gt; 111
[1] => 222.
)
2
Tip: The func_get_args () function is used to obtain the parameters passed in to the function. an array is returned. the func_num_args () function gets the number of parameters in the input function.
Next let's take a look at call_user_func_array. This function is also used when a function needs to be called dynamically. its usage is similar to that of the call_user_func function, but the parameter is passed in an array. The example is as follows:
The call_user_func_array function can also call internal methods of the class, such:
The following is an example of dynamic function call:
The readers of the above examples can be more impressed when they can run them on their own.
Articles you may be interested in
- PHP filter_var () function Filter function
- Use php functions in the smarty template and how to use multiple functions for a variable in the smarty Template
- Php prompts Call to undefined function curl_init () error solution
- JavaScript array operation function summary (push, pop, join, shift, unshift, slice, splice, concat)
- Php uses the filter function to verify the mailbox, url, and IP address
- PHP generates continuous numbers (letters) array function range () analysis, PHP lottery program function
- Use the PHP function memory_get_usage to obtain the current PHP memory consumption for program performance optimization.
- Fatal error Call to undefined function date_default_timezone_set ()
The Destroy () function was also encountered in the discuz Forum code last year. Today, it is on the internet...