Loop to create form
I want to create a for loop to create 10 text inputs with unique names/ids. Currently I am using the following code.
<?php
for ($i = 0; $i < 10; $i++) {
echo "<input name='person'" + $i + "' type='text' id='person'" + $i + "' /><br />开发者_开发问答";
}
?>
Now it just outputs the number in the loop, but doesn't output any inputs.
Thanks.
Concatenation in php is done via '.' and not '+'
<?php
for ($i = 0; $i < 10; $i++) {
echo "<input name='person". $i . "' type='text' id='person" . $i . "' /><br />";
}
?>
I think you have a slight error in your HTML attribute syntax, so your quote marks are in the wrong place.
<?php
for ($i = 0; $i < 10; $i++) {
echo "<input name='person" + $i + "' type='text' id='person" + $i + "' /><br />";
}
?>
精彩评论