cloudnyn3 Posted May 1, 2013 Share Posted May 1, 2013 Hi there, so I'm having a little trouble understanding looping and arrays or inputs. I'm a Pshell programmer and things are done MUCH differently lol So heres the script I've created. <?php $first=400; $second=300; for ($i = $first; $second < $i; $i++) { echo $i; } ?> What I'm trying to accomplish is taking the first Number and the second and get it to count or "loop" up to 400 from the lower number. Then have it output the result. I'm not sure what I'm doing wrong here though...... Quote Link to comment https://forums.phpfreaks.com/topic/277508-help-understanding-array-and-input-looping/ Share on other sites More sharing options...
requinix Posted May 1, 2013 Share Posted May 1, 2013 It counts up from 400 and never ends? The for loop will keep running as long as $second for ($i = $second /* the lower number */; $i Quote Link to comment https://forums.phpfreaks.com/topic/277508-help-understanding-array-and-input-looping/#findComment-1427593 Share on other sites More sharing options...
cloudnyn3 Posted May 1, 2013 Author Share Posted May 1, 2013 It counts up from 400 and never ends? The for loop will keep running as long as $second < $i; $second=300 and $i=400, but $i only counts up (the $i++) so it'll never drop below $second. for ($i = $second /* the lower number */; $i <= $first /* keep going while $i doesn't exceed $first */; $i++ /* counts up */) { Ah thank you, that was my mistake for not paying attention. So when it outputs, its just a long ass string of numbers. like REALLY long. shouldn't it just stop and output the value of the 2nd number? which would in theory be 400 now that its incremented up? Quote Link to comment https://forums.phpfreaks.com/topic/277508-help-understanding-array-and-input-looping/#findComment-1427605 Share on other sites More sharing options...
Barand Posted May 1, 2013 Share Posted May 1, 2013 It does what you tell it to do. In this case echo the value of $i each iteration of the loop. It sounds like you want $first = 400; $second = 300; $i = $first; No long list of numbers and $i ends up with the value of $first Quote Link to comment https://forums.phpfreaks.com/topic/277508-help-understanding-array-and-input-looping/#findComment-1427610 Share on other sites More sharing options...
cloudnyn3 Posted May 2, 2013 Author Share Posted May 2, 2013 It does what you tell it to do. In this case echo the value of $i each iteration of the loop. It sounds like you want $first = 400; $second = 300; $i = $first; No long list of numbers and $i ends up with the value of $first esentially what I'm doing is this <?php $first=400; $second=300; echo "$first - $second"; ?> I'm looking to do it using a loop around? Quote Link to comment https://forums.phpfreaks.com/topic/277508-help-understanding-array-and-input-looping/#findComment-1427764 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.