Understanding of callback function (I)

Time:2022-5-3

The elegant code processing methods used in too many frameworks on the market now dazzle developers, which puts higher requirements on the quality of framework users. In fact, the elegant methods used in the framework have the most basic sources, but it is not the framework author who fully integrates them into the bottom of the framework. Let’s get rid of the clouds and see the essence of the code. Let me talk about the callback function:

Definition of callback functionUnderstanding of callback function (I)

Callback function is to pass the name of another function as a parameter when calling a function, and call it in the function body

You can understand the response through the following code examples:

function study($username){
    echo $username."is studying PHP basic courses.<br>"
}

function dowhat($funcname,$username){
    $funcname ($username) // declare and apply callback functions using variable functions
}
dowhat('study','Max')

I believe that through the description of the above code, we have a clear understanding of the callback function.Understanding of callback function (I) Understanding of callback function (I) Understanding of callback function (I)

In fact, in the world of PHP, there are already functions that can call callback functions. They are

call_user_func(funcName,params...)
call_user_func_array(funcName,array)

For the use of these two functions, I will not repeat the response.

If you work hard every day, you will be closer to success.Understanding of callback function (I) Understanding of callback function (I)Understanding of callback function (I)

This work adoptsCC agreement, reprint must indicate the author and the link to this article