underline Posted October 10, 2009 Share Posted October 10, 2009 I am trying to create a script that repeats a string a certain amount of times, but I also needed a value in the string to increment up one each time it repeats. I'm trying to make it so that it creates 6 check boxes, but changes the name of the checkbox, as well as the label of it. I tried using functions, but I'm not all that familiar with functions to get that to work. I've also tried using str_repeat (that I have below), but still have no idea how to increase $candidate or c1. Any help would be appreciated $canamts = 6; echo str_repeat("<label><input type='checkbox' name='c1' onClick='return KeepCount()' value='1' id='votes_0' />$candidate1</label><br>",$canamts); Link to comment https://forums.phpfreaks.com/topic/177177-repeating-a-string-x-amount-of-times-with-a-value-changing-each-new-time/ Share on other sites More sharing options...
Daniel0 Posted October 10, 2009 Share Posted October 10, 2009 Use a for loop and use the counter for that. Link to comment https://forums.phpfreaks.com/topic/177177-repeating-a-string-x-amount-of-times-with-a-value-changing-each-new-time/#findComment-934206 Share on other sites More sharing options...
ameyemad Posted October 10, 2009 Share Posted October 10, 2009 for ($i=0;$i<10;$i++){ $candidate=1; $c1=1; $canamts = 6; echo"<label><input type='checkbox' name='$c1' onClick='return KeepCount()' value='1' id='votes_0' />$candidate</label><br>"; $c1++; $candidate++; } you can change 10 to anything you like. is that what you want? Link to comment https://forums.phpfreaks.com/topic/177177-repeating-a-string-x-amount-of-times-with-a-value-changing-each-new-time/#findComment-934207 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.