Jump to content

Repeating a string x amount of times with a value changing each new time


underline

Recommended Posts

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  :shy:

 

$canamts = 6;
echo str_repeat("<label><input type='checkbox' name='c1' onClick='return KeepCount()' value='1' id='votes_0' />$candidate1</label><br>",$canamts);

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.