PHP的算法来打印一个AA AAA AAA AAB直到ZZZ [英] php Algorithm to print a aa aaa ab aab till zzz
本文介绍了PHP的算法来打印一个AA AAA AAA AAB直到ZZZ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从a到zzz最多打印3个字母,例如我的输出应该是
Hi i need To print from a to zzz upto 3 letters , for example my output should be
A
B
.
.
.
Z
AA
AB
.
.
AZ
BA
BB
.
.
.
ZZ
AAA
AAB
.
.
.
.
ZZZ
过去5个小时我一直在努力,找不到任何逻辑,并且尝试使用下面的代码
I was trying hard for past 5 hours , I cant find any logic and i tried below code
<?php
for ($i=65; $i<=90; $i++) {
for ($i=65; $i<=90; $i++) {
for ($i=65; $i<=90; $i++) {
echo chr($i).chr($i).chr($i)."<br>";
}
}
}
?>
推荐答案
PHP具有一项便捷的功能,可以根据您的描述完全增加字符串的工作量.
PHP has a convenient feature where incrementing a string works exactly as you describe.
因此,您所需要做的就是:
So all you need is:
for( $i="A"; $i!="ZZZ"; $i++) {
echo $i."<br />";
}
修改后的解决方案,最后打印"ZZZ"(而不是"ZZY"):
revised solution that prints 'ZZZ' (instead of 'ZZY') last:
$i = 'A';
do {
echo $i . '<br />';
} while ( $i++ != 'ZZZ' );
这篇关于PHP的算法来打印一个AA AAA AAA AAB直到ZZZ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文