What exactly is a PHP callback function, and how do I fix it?

Source: Internet
Author: User
What exactly is a PHP callback function?
Baidu a bit, a lot of callbacks are said to use a function pointer callback, and then step by step, finally comes down to the C language, no language! Is this callback so hard to understand?
My understanding callback, the key is this back, what back? Some people understand that this is called a function inside the function again, I think it is not so, but I call myself, like the mathematical logic of the loop proof, such as
Conditions............ Verification: a=b;
Sometimes we make this kind of verification error: because B=a, so a=b, believe that the individual has made a similar mistake
And the callback function I understand like this,
function fn ($a) {
$b =m;
$c = $b +FN ($b);
Return
}
And I don't know what I understand, right?

Share to: more


------Solution--------------------
Your understanding is wrong!
Call yourself "recursion" instead of callback

And you know that the key to the callback is this back.
Since it is back, then there is the question of who is the subject, because the callback is the meaning of the call backwards
I called function A, and function a called the function B I provided during execution, which is called function A's callback function.
Obviously the subject is function a

We know that a function is a collection of code that accomplishes a particular function, and in the process of executing a function, it is generally not possible to interfere with his behavior.
When a function is designed with a callback function, it is possible to intervene with the callback function during the execution of the function. For example
function foo ($n, $f = ") {
if ($n < 1) return;
for ($i =0; $i < $n; $i + +) {
Echo $f? $f ($i): $i;
}
}
When there is no callback
Foo (5); 01234

When there is a callback
Function F1 ($v) {
return $v + $v;
}
Foo (5, ' F1 '); 02468
  • 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.