Call user func () and Call_user_func_array () Invoke Custom Function summary in PHP

Source: Internet
Author: User

Call_user_func () and Call_user_func_array (), by passing in a string function, can invoke a custom function and support references, allowing the user to invoke a custom function and pass in a certain parameter:

1.Mixed Call_user_func (callable $callback [, Mixed $parameter [, mixed $ ...])

The first parameter is the custom function name, and the following argument is the function's argument, and the return value is the result of the custom function.

function Say ($wordecho$word;} Call_user_func (' Say ', ' Hello World '// output//hello World

Of course, you can also call methods in the class:

Classfunction SayHello ($word = ") {  echo$word;}}   // Note that it must be instantiated, unless it is a static $world New World (); Call_user_func ([$world, ' SayHello '], ' Hello World '// output Hello world

Note: The way the array is written above [], if the PHP version is below PHP5.4, use Array ()

2. Mixed Call_user_func_array (callable $callback, array $param _arr)

The call user func () is actually the same as the function, but only a slight difference in the parameters, this is actually from the name of the method can be seen out:

function Say ($wordecho$word;} Call_user_func_array // Note: The second parameter is the form of an array//output//hello World
Classfunction SayHello ($word = ") {  echo$word;}}   // Note that it must be instantiated, unless it is a static $world New World (); Call_user_func_array ([$world// Note: The second parameter is an array form//output Hello world

Call user func () and Call_user_func_array () Invoke Custom Function summary in PHP

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.