How to write reverse order output method in php

藏色散人
Release: 2023-03-13 17:54:02
Original
5655 people have browsed it

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.

How to write reverse order output method in php

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)
}
Copy after login

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 &#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;;
}
}
Copy after login

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!

Related labels:
php
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