perezf Posted August 6, 2008 Share Posted August 6, 2008 how can i loop through letters for instance aaa aab aac aad etc...?? I know how to do it with numbers but not letters Link to comment https://forums.phpfreaks.com/topic/118362-solved-looping-through-letters/ Share on other sites More sharing options...
DarkWater Posted August 6, 2008 Share Posted August 6, 2008 I don't see why not. $letters = range('a', 'z'); foreach($letters as $letter) { echo $letter . "\n"; } Link to comment https://forums.phpfreaks.com/topic/118362-solved-looping-through-letters/#findComment-609130 Share on other sites More sharing options...
perezf Posted August 6, 2008 Author Share Posted August 6, 2008 that only works for a b c d e f g etc... i need aaa aab aac aad aae aaf ... aba abb etc... how can i pull that off Link to comment https://forums.phpfreaks.com/topic/118362-solved-looping-through-letters/#findComment-609134 Share on other sites More sharing options...
DarkWater Posted August 6, 2008 Share Posted August 6, 2008 You can try: <?php $letters = range('a', 'z'); for ($first=0;$first<count($letters);$first++){ $firstletter = $letters[$first]; for ($second=0;$second<count($letters);$second++){ $secondletter = $letters[$second]; for ($third=0;$third<count($letters);$third++) { $thirdletter = $letters[$third]; echo $firstletter . $secondletter . $thirdletter . "<br />"; } } } ?> That's what I thought up in about 30 seconds. I mean I could probably right some recursive function that just makes a large array that you can loop through, but I'm kind of in a non-thinking state at the moment. Btw, I just tested that code and it works. xD Link to comment https://forums.phpfreaks.com/topic/118362-solved-looping-through-letters/#findComment-609138 Share on other sites More sharing options...
perezf Posted August 6, 2008 Author Share Posted August 6, 2008 Niceeee. Thank you very much it worked great Link to comment https://forums.phpfreaks.com/topic/118362-solved-looping-through-letters/#findComment-609165 Share on other sites More sharing options...
DarkWater Posted August 6, 2008 Share Posted August 6, 2008 Wow I cannot believe I said "right" instead of "write". I just finished writing a letter in Greek to send to a friend and now I can't think straight. >_< Not sure why. xD Excuse the incorrect word from the previous post. =P Link to comment https://forums.phpfreaks.com/topic/118362-solved-looping-through-letters/#findComment-609168 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.