当前位置:Gxlcms > PHP教程 > phpforeach正序倒序输出示例

phpforeach正序倒序输出示例

时间:2021-07-01 10:21:17 帮助过:11人阅读

php foreach正序倒序输出

例子:

  1. // 正序
  2. foreach($files as $file_num => $file) {
  3. if(is_file($directory.$file)){
  4. //$file = iconv("gb2312","UTF-8",$file); //或者 iconv("gb2312","UTF-8",$value);
  5. $date = substr($file,0,9);
  6. echo '
  7. ';
  8. echo '';
  9. echo '';
  10. echo '';
  11. echo '
  12. ';
  13. }
  14. }
  15. // 倒序
  16. foreach(array_reverse($files) as $file_num => $file) {
  17. if(is_file($directory.$file)){
  18. //$file = iconv("gb2312","UTF-8",$file); //或者 iconv("gb2312","UTF-8",$value);
  19. $date = substr($file,0,9);
  20. echo '
  21. ';
  22. echo '';
  23. echo '';
  24. echo '';
  25. echo '
  26. ';
  27. }
  28. }

人气教程排行