mrras25 Posted October 1, 2008 Share Posted October 1, 2008 I just can not wrap my mind around it at this point... I have a couple of for loops and what I need to do is create a numbered sequence that assigns a number to 2 strings after the second one it needs to increment by 1. (since I am speaking in circles here is an example) for($h = 1; $h < 5; $h++) { $numb = (100*$h); for($i = 1; $i < 17; $i++) { $secNumb = ($numb +20); echo "First NUMBER: ".($i +$numb)."Second Number: ".$secNumb."\n"; //The Second number needs to be displayed twice see below for example and this is where i need help } } First NUMBER: 101 Second Number: 120 First NUMBER: 102 Second Number: 120 First NUMBER: 103 Second Number: 121 First NUMBER: 104 Second Number: 121 First NUMBER: 105 Second Number: 122 First NUMBER: 106 Second Number: 122 ... Link to comment https://forums.phpfreaks.com/topic/126688-probably-simple-loop-question/ Share on other sites More sharing options...
aeonsky Posted October 1, 2008 Share Posted October 1, 2008 <?PHP $numbers = 6; $second = 120; for($i = 1; $i <= $numbers; $i++) { $first = $i + 100; echo "FIRST NUMBER: $first SECOND NUMBER: $second \n"; if ($first % 2 == 0) $second++; } ?> Produced this output: FIRST NUMBER: 101 SECOND NUMBER: 120 FIRST NUMBER: 102 SECOND NUMBER: 120 FIRST NUMBER: 103 SECOND NUMBER: 121 FIRST NUMBER: 104 SECOND NUMBER: 121 FIRST NUMBER: 105 SECOND NUMBER: 122 FIRST NUMBER: 106 SECOND NUMBER: 122 Link to comment https://forums.phpfreaks.com/topic/126688-probably-simple-loop-question/#findComment-655214 Share on other sites More sharing options...
mrras25 Posted October 2, 2008 Author Share Posted October 2, 2008 Thank you so much, sorry I didn't get back sooner with the amount of nested loops I have going here (because it has to be!) it took me a little longer to apply the logic you displayed to me... Many Thanks to you!!!! -> Your a mother bloody GENIUS!!!!! Link to comment https://forums.phpfreaks.com/topic/126688-probably-simple-loop-question/#findComment-655734 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.