Blogger Information
Blog 4
fans 0
comment 0
visits 1577
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
2021年8月6日作业:回调函数和递归函数的认识
泉懿
Original
325 people have browsed it

1,回调函数

回调函数就是在一个函数中把另外一个函数当做参数传递进来度执行,执行完之后再回到本函数继续执行后面的内容

  1. function a(int $a,int $b)
  2. {
  3. return $a+$b;
  4. }
  5. $c=call_user_func('a',1,2)
  6. {
  7. echo $c;
  8. }

2,递归函数

递归函数就是在一个函数内部调用自已,但是要在函数内部设置条件用来中断递归调用,否者会引起死循环。

  1. function a()
  2. {
  3. static $b=0;
  4. if ($b<10):
  5. echo $b;
  6. a();
  7. endif;
  8. }
  9. $c=a();
  10. echo $c;
Correcting teacher:PHPzPHPz

Correction status:unqualified

Teacher's comments:写的递归函数是一个死循环,作业应该注释如何跳出当前的递归循环
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post