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
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 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 />";
}
EDIT: revised solution that prints 'ZZZ' (instead of 'ZZY') last:
$i = 'A';
do {
echo $i . '<br />';
} while ( $i++ != 'ZZZ' );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With