How to write reverse output in php: 1. Create a PHP sample file; 2. Pass "for ($i=1; $i<=strlen($str); $i ){echo substr($ str , -$i , 1)}" method to reverse the string.
The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer
How to write the reverse output method in php?
1. If it is a string or an array directly, you can use strrev or array_reverse to reverse it respectively.
2. Write an algorithm yourself to reverse the string.
$str = "abcdef"; for ( $i=1; $i<=strlen($str); $i++) { echo substr($str , -$i , 1) }
php positive sequence output sample code
Implementation code:
// 正序 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 '<li class="world-cup-'.$date.'">'; echo '<a href="'.$directory.$file.'" rel="worldcup" title="巴西世界杯赛事'.$date.'">'; echo '<img src="'.$directory.$file.'" alt="">'; echo '</a>'; echo '</li>'; } }
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to write reverse order output method in php. For more information, please follow other related articles on the PHP Chinese website!