Home  >  Article  >  Backend Development  >  php foreach output in forward and reverse order

php foreach output in forward and reverse order

巴扎黑
巴扎黑Original
2016-11-12 11:17:291518browse

// 正序
foreach($files as $file_num => $file) {
if(is_file($directory.$file)){
//$file = iconv("gb2312","UTF-8",$file);  //或者 iconv("gb2312","UTF-8",$value);
$date = substr($file,0,9);
echo &#39;<li class="world-cup-&#39;.$date.&#39;">&#39;;
echo &#39;<a href="&#39;.$directory.$file.&#39;" rel="worldcup" title="巴西世界杯赛事&#39;.$date.&#39;">&#39;;
echo &#39;<img src="&#39;.$directory.$file.&#39;" alt="">&#39;;
echo &#39;</a>&#39;;
echo &#39;</li>&#39;;
}
}
// 倒序
foreach(array_reverse($files) as $file_num => $file) {
if(is_file($directory.$file)){
//$file = iconv("gb2312","UTF-8",$file);  //或者 iconv("gb2312","UTF-8",$value);
$date = substr($file,0,9);
echo &#39;<li class="world-cup-&#39;.$date.&#39;">&#39;;
echo &#39;<a href="&#39;.$directory.$file.&#39;" rel="worldcup" title="巴西世界杯赛事&#39;.$date.&#39;">&#39;;
echo &#39;<img src="&#39;.$directory.$file.&#39;" alt="">&#39;;
echo &#39;</a>&#39;;
echo &#39;</li>&#39;;
}
}

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