eddieadams Posted May 28, 2009 Share Posted May 28, 2009 1 12 123 12345 2 23 234 2345 3 34 345 4 45 5 Nested loops? Or can this be done simpler. 5+4+3+2+1 = 14 possible combinations Quote Link to comment https://forums.phpfreaks.com/topic/160074-nested-loops-making-pattern/ Share on other sites More sharing options...
.josh Posted May 28, 2009 Share Posted May 28, 2009 depending on what you're really wanting to do with this, it might have to be altered a bit, but the hard part is there. <?php $num = 5; $pos = 1; for ($a = 1; $a <= $num; $a++) { while ($pos <= $num) { for ($b = $a; $b <= $pos; $b++) { echo $b; } echo "<br/>"; $pos++; } $pos = 1; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/160074-nested-loops-making-pattern/#findComment-844537 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.