Today accidentally in the official document of CodeIgniter again see PHP call_user_func_array () This function, last year also in the Discuz Forum code also encountered, today on the Internet to check the use of this function, Let's share with you the usage of the Call_user_func_array and Call_user_func functions, plus a description of the Func_get_args () function and the Func_num_args () function.
The Call_user_func function is used when the function needs to be called dynamically, and this function has two uses, as explained below:
(1) Call the function of loneliness:
(2) Calling functions inside the class:
In the example above, the result output is as follows:
Array
(
[0] = 111
[1] = 222
)
2
Tip: the Func_get_args () function is to get the arguments passed into the function, returning an array, and the Func_num_args () function gets the number of arguments in the passed-in function.
Let's take a look at Call_user_func_array, which is also used when the function needs to be called dynamically, and its usage and CALL_USER_FUNC functions are compared, except that the parameters are passed in an array, as shown in the following example:
The Call_user_func_array function can also invoke methods inside the class, such as:
Let's look at an example of a dynamic call function:
The above example readers will be more impressed when they run their own operations.
Articles you may be interested in
- PHP Filter_var () function Filter function
- Use PHP functions in Smarty Templates and how to use multiple functions for a variable in a smarty template
- PHP tips for solutions to undefined function curl_init () errors
- JavaScript Array Operation function Summary (PUSH,POP,JOIN,SHIFT,UNSHIFT,SLICE,SPLICE,CONCAT)
- Php method for verifying mailboxes, URLs, and IP addresses using the filter function
- PHP generates consecutive numbers (Letters) array function range () analysis, PHP lottery program function
- Use PHP function memory_get_usage to get the current PHP memory consumption to achieve program performance optimization
- Fatal error call to undefined function date_default_timezone_set ()
http://www.bkjia.com/PHPjc/764114.html www.bkjia.com true http://www.bkjia.com/PHPjc/764114.html techarticle today accidentally in the official document of CodeIgniter again see PHP call_user_func_array () This function, last year also in the Discuz Forum code also encountered, today in the Web ...