jj20051 Posted July 24, 2009 Share Posted July 24, 2009 How would you go about listing all of the numbers between x and y. (referring to random numbers) So for example, the numbers are 1 and 12 get php to list: 2 3 4 5 6 7 8 9 10 11 Before anyone asks I searched google several times. Link to comment https://forums.phpfreaks.com/topic/167250-list-all-numbers-between/ Share on other sites More sharing options...
mattal999 Posted July 24, 2009 Share Posted July 24, 2009 <?php $min = 2; $max = 12; $i = 0; while ($i < $max) { $i++; if($i =< $max && $i >= $min) { echo $i . ", "; } } ?> Just threw that together. May work. May not. Link to comment https://forums.phpfreaks.com/topic/167250-list-all-numbers-between/#findComment-881836 Share on other sites More sharing options...
haku Posted July 24, 2009 Share Posted July 24, 2009 It will work, but it's a little wordy (can you say wordy about code? ) $min = 5; $max = 10; for($i = $min + 1; $i < $max; $i++) { echo $i; } Link to comment https://forums.phpfreaks.com/topic/167250-list-all-numbers-between/#findComment-881838 Share on other sites More sharing options...
Mark Baker Posted July 24, 2009 Share Posted July 24, 2009 $min = 2; $max = 12; echo implode(', ',range($min+1,$max-1)); Link to comment https://forums.phpfreaks.com/topic/167250-list-all-numbers-between/#findComment-881857 Share on other sites More sharing options...
haku Posted July 24, 2009 Share Posted July 24, 2009 Nice Link to comment https://forums.phpfreaks.com/topic/167250-list-all-numbers-between/#findComment-881889 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.