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

PHP foreach forward and reverse order output example

WBOY
WBOYOriginal
2016-07-25 09:12:001742browse

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


Statement:
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