watthehell Posted September 14, 2007 Share Posted September 14, 2007 hi, i was doing a for.. loop which comes at 10 interval and populate a list box, can anyone guide me i write this didn't work <? for($i=10;$i<=60;$i++){?> <option value="<?=$i+9;?>"><? echo $i;?></option> <? }?> the output should be like this 00 10 20 30 40 50 any help.. plz Link to comment https://forums.phpfreaks.com/topic/69321-solved-forloop-question/ Share on other sites More sharing options...
Barand Posted September 14, 2007 Share Posted September 14, 2007 <?php for ($i=0; $i<60; $i+=10) { printf ("<option value='%02d'>%02d</option>\n", $i, $i); } ?> Link to comment https://forums.phpfreaks.com/topic/69321-solved-forloop-question/#findComment-348323 Share on other sites More sharing options...
watthehell Posted September 14, 2007 Author Share Posted September 14, 2007 Thanks a lot <?php for ($i=0; $i<60; $i+=10) { printf ("<option value='%02d'>%02d</option>\n", $i, $i); } ?> Can you explain this please printf ("<option value='%02d'>%02d</option>\n", $i, $i); what is %02d for anyway thanks it worked.. Link to comment https://forums.phpfreaks.com/topic/69321-solved-forloop-question/#findComment-348328 Share on other sites More sharing options...
hostfreak Posted September 14, 2007 Share Posted September 14, 2007 The manual can explain it better than I can, so: http://www.php.net/manual/en/function.sprintf.php . Take a look at the format parameter explanation. Link to comment https://forums.phpfreaks.com/topic/69321-solved-forloop-question/#findComment-348330 Share on other sites More sharing options...
Barand Posted September 14, 2007 Share Posted September 14, 2007 But basically it says print as a 2 digit integer with leading zeros, so "0" becomes "00" and "10" etc stay as "10" (already 2 digits) Link to comment https://forums.phpfreaks.com/topic/69321-solved-forloop-question/#findComment-348340 Share on other sites More sharing options...
watthehell Posted September 14, 2007 Author Share Posted September 14, 2007 Thanks a lot for your help... Closing this thread now.. Link to comment https://forums.phpfreaks.com/topic/69321-solved-forloop-question/#findComment-348347 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.