Home > Backend Development > PHP Tutorial > PHP foreach forward and reverse order output example

PHP foreach forward and reverse order output example

WBOY
Release: 2016-07-25 09:12:00
Original
1752 people have browsed it

php foreach output in forward and reverse order

Example:

  1. // Positive sequence
  2. foreach($files as $file_num => $file) {
  3. if(is_file($directory.$file)){
  4. //$file = iconv ("gb2312","UTF-8",$file); //or 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. // Reverse order
  16. foreach(array_reverse($files) as $file_num => $file) {
  17. if(is_file($directory.$file)){
  18. //$file = iconv("gb2312","UTF-8",$file); //or 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. }
Copy code


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template