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

回调函数与递归函数的理解

一、回调函数

1、将一个用户自定的”执行过程”当做参数传递给到函数中,大大增大了对该函数功能的扩展
2、调用函数时不传递标准的变量作为参数,而是将另一个函数作为参数传递到调用的函数中。

  1. <?php
  2. $func=function($name1,$name2)
  3. {
  4. return $name1+$name2;
  5. };
  6. function test(Closure $callback){
  7. $name1=1;
  8. $name2=5;
  9. echo $callback($name1,$name2);
  10. };
  11. echo test($func);
  12. ?>

二、递归函数

  1. <?php
  2. function del($dir)
  3. {
  4. if(is_dir($dir))
  5. {
  6. $flag = false;
  7. if($handle = opendir($dir))
  8. {
  9. while (($file = readdir($handle)) !== false){
  10. if($file != '.' && $file != '..' )
  11. {
  12. if(is_dir($dir.'\\'.$file)){
  13. delete_dir_file($dir.'\\'.$file);
  14. }else{
  15. unlink($dir.'\\'.$file);
  16. }
  17. }
  18. }
  19. }
  20. closedir($handle);
  21. if(rmdir($dir))
  22. {
  23. $res = true;
  24. }
  25. }
  26. return $res;
  27. }
  28. $path = __DIR__ ;
  29. delete_dir_file($app_path);
  30. ?>

递归函数还是只是仅仅学了一点,还得继续学习,加油。

Correcting teacher:PHPzPHPz

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