开发者

Loop to create form

开发者 https://www.devze.com 2023-04-09 10:52 出处:网络
I want to create a for loop to create 10 text inputs with unique names/ids. Currently I am using the following code.

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

精彩评论

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