Jump to content

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


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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.