Call_user_func function and Call_user_func_array function parsing _php Tutorial

Source: Internet
Author: User
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 ...

  • 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.