来自数组的PHP动态按钮值

时间:2017-06-02 11:18:40

标签: php

这是我的问题:

    echo '<form class="dugme" method="post" name="$b" value="">
<button type="submit">Pusti</button>
</form>';

我已经定义了$ b变量,并希望在页面上使用for循环绘制它($ b = 0; $ b&lt; = 10; $ b ++)。

但是在&#34; &#34;,&#39; &#39; ...我的名字=&#34; $ b&#34; ;

我的代码:

for ($b=0; $b <= 10; $b++){
echo '<form class="dugme" method="post" name="$b" value="">
<button type="submit">Pusti</button></form>';
}

1 个答案:

答案 0 :(得分:1)

你需要正确连接

for ($b=0; $b <= 10; $b++){
echo '<form class="dugme" method="post" name="'.$b.'" value="'.$b.'">
<button type="submit">Pusti</button></form>';
}

注意:在单引号内,所有内容都视为字符串。你需要逃避它,或者你需要像这样连接