Blogger Information
Blog 43
fans 0
comment 0
visits 30486
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
回调函数、递归函数
橙絮圆
Original
561 people have browsed it

回调函数、递归函数

作业标题:0806 PHP编程作业
作业内容:请实例演绎你对回调函数与递归函数的理解?


  • 回调函数
    1. <?php
    2. $func=function ($a,$b){
    3. return $a+$b;
    4. };
    5. function test ($callback){
    6. return $callback;
    7. }
    8. echo test($func(10,20));
    9. echo "<br>";
    10. function test1 (string $name){
    11. return "我的名字叫:".$name;
    12. }
    13. echo call_user_func('test1',"小明");
    14. ?>
  • 递归函数
    1. <?php
    2. function delete_dir_file($dir)
    3. {
    4. //声明一个初始状态 默认情况下缓存未被删除
    5. $res = false;
    6. if(is_dir($dir))
    7. {
    8. //成功打开目录流
    9. if($handle = opendir($dir))
    10. {
    11. while (($file = readdir($handle)) !== false){
    12. if($file != '.' && $file != '..' )
    13. {
    14. if(is_dir($dir.'\\'.$file)){
    15. delete_dir_file($dir.'\\'.$file);
    16. }else{
    17. //unlink只能删除一个文件
    18. unlink($dir.'\\'.$file);
    19. }
    20. }
    21. }
    22. }
    23. //关闭目录句柄
    24. closedir($handle);
    25. //目录只有为空的情况下才能被直接删除
    26. if(rmdir($dir))
    27. {
    28. $res = true;
    29. }
    30. }
    31. return $res;
    32. }
    33. $app_path = __DIR__ ;
    34. delete_dir_file($app_path);
    35. ?>
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