Blogger Information
Blog 19
fans 0
comment 0
visits 10105
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
回调函数与递归函数的理解
bloght5386
Original
476 people have browsed it

请实例演绎你对回调函数与递归函数的理解?

  1. //回调函数
  2. function getVal($a,$b,$c){
  3. //调用另一个函数
  4. return $c($a,$b); //可变函数;
  5. }
  6. function sum($a,$b){
  7. return $a+$b;
  8. }
  9. echo getVal(3,4,'sum');
  10. /**
  11. 案例:斐波那契数列
  12. 说明:第1数和第2个数都是1,从第3个数开始,是前两个数的和;
  13. 1 1 2 3 5 8 13 21 34 55.............
  14. 问:当给位置数字时,返回是结果;
  15. */
  16. function abc($a){
  17. if($a == 1 || $a == 2){
  18. return 1;
  19. }else{
  20. return abc($a-1) + abc($a-2); //裂变;
  21. }
  22. }
  23. $res = abc(4);
  24. echo $res;
Correcting teacher:灭绝师太灭绝师太

Correction status:qualified

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