开发者

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 />";
    }
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜