What is a PHP callback function?

Source: Internet
Author: User
What is the PHP callback function? Baidu: a lot of callbacks are called by function pointers. Next, I will talk about it step by step. Finally, it comes down to the C language. it's speechless! Is this callback so hard to understand?
What is the key to Callback? Some people understand that this is another function called inside the function. in my opinion, this is not the case. Instead, I call myself, just like the loop proof in the mathematical logic, such
Conditions ............ Verification: a = B;
Sometimes we will make such a verification error: Because B = a, so a = B, I believe that all people have made similar mistakes.
The callback function is similar to this in my understanding,
Function fn ($ ){
$ B = m;
$ C = $ B + fn ($ B );
Return;
}
I don't know what I understand, right?


Reply to discussion (solution)

Your understanding is wrong!
Call a callback instead of calling a callback.

You also know that the key to callback is this callback.
Since it is a callback, there is a question about who is the subject, because the callback is called back.
I called function A, and function A called function B during execution. function B is called the callback function of function.
Obviously, the subject is function.

We know that a function is a set of code that completes a specific function. During function execution, it generally cannot interfere with its behavior.
When a function is designed with a callback function, we may intervene in the function during its execution. For example

Function foo ($ n, $ f = '') {if ($ n <1) return; for ($ I = 0; $ I <$ n; $ I ++) {echo $ f? $ F ($ I): $ I ;}// foo (5) when no callback is available; // 01234 // function f1 ($ v) when a callback is available) {return $ v + $ v;} foo (5, 'F1'); // 02468

Your understanding is wrong!
Call a callback instead of calling a callback.

You also know that the key to callback is this callback.
Since it is a callback, there is a question about who is the subject, because the callback is called back.
I called function A, and function A called function B during execution. function B is called the callback function of function.
Obviously, the subject is function.

We know that a function is a set of code that completes a specific function. During function execution, it generally cannot interfere with its behavior.
When a function is designed with a callback function, we may intervene in the function during its execution. For example

Function foo ($ n, $ f = '') {if ($ n <1) return; for ($ I = 0; $ I <$ n; $ I ++) {echo $ f? $ F ($ I): $ I ;}// foo (5) when no callback is available; // 01234 // function f1 ($ v) when a callback is available) {return $ v + $ v;} foo (5, 'F1'); // 02468


Why can I call the f1 function without passing parameters?
What role does this function play on the first function?

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.