Callback functions and variables can be used with an anonymous function to achieve a more beautiful and complex a functional structure. Marble platform price
Callback function, that is, when dealing with a function, let me make this function to customize the number of ability, my permission to call this function, you can also pass a function with the assist in the process.
This chapter is a variable and callback functions combined.
? <PHP function woziji ($ One, $ TWO, $ func) { // I provides that: Check if $ func is a function of, if not the function to stop the implementation of the sections of the code, return false IF (is_callable ($ func)!) { return false; } // I put $ one, $ two added together, then $ one and $ two incoming $ func handle this function once // $ func is a function of variable, variable functions see chapter echo $ one + TWO FUNC + $ $ ($ One, $ TWO); } // we try several functions defined function plusx2 ($ foo, $ bar) { $ Result = ($ + $ foo bar) * 2; return $ Result; } Jian function ($ X, Y $) { $ Result = X $ - $ Y; return $ Result; } // at the function call, woziji, which try to pass parameters echo woziji (20,10, 'plusx2' ) ; // try jian into the plusx2 results echo woziji (20,10, 'jian' ); ?>
The process is this:
1. 20 assigned to the parameter $ one, 10 assigned to the $ TWO, and these two variables jian plusx2 or functions assigned to the $ func
2. judge plusx2 in woziji this function is a function of whether or jian, not the function will return false to stop the execution
The display plusx2 jian or a function. Thus $ one = 20, $ two = 10 are added, and after the addition, and $ $ One TWO and brought to the $ func ($ one, $ two) of.
4. brought to the inside and $ FUNC, is variable, or may be plusx2 jian. If it is plusx2, $ one = 20, $ two = 10. This result gave two plusx2 function inside $ foo $ bar and
5. $ foo + $ bar multiplied by 2 after the operation returns to the function-body woziji: $ one + $ two + $ func ($ one, $ two);
6. In this way the main operation result obtained
Now that we understand the callback function: In a number of tone inside, and then pass a function name, the function name () brackets. Identified as a function of variables, with the implementation.