doutang6819 2013-05-27 15:26
浏览 73
已采纳

正确输出php数组到html代码

I have this piece of code where I need to output some $_POST values into HTML. Nothing happens in the output line (see comment inside the code), even though var_dump() shows that the needed values are in the array and under the desired indexes.

The trick is that the array indexes for the required data depend on the counter $i. I'm feeling like there is some really stupid and basic syntax mistake in this code. Please help me, oh almighty Hivemind!

while ($i < $somespecificvar) 
{ 
    if (($i != 0) AND ($i < $somespecificvar)) 
    {
        echo "
<td></td>
";
    }

    echo "<td>";

    if ($_POST["text_l$i"] != 0)
    {
        echo "{$_POST['text_l$i']}, {$_POST['l$i']}";// NOTHING HAPPENS OVER HERE
    }

    echo "</td>";
    $i++;
}
  • 写回答

1条回答 默认 最新

  • douye1876 2013-05-27 15:30
    关注

    In PHP, you can use the {$variable} inside a "" string, however it can only really handle basic variables. Change it so it's like so:

    echo $_POST['text_l' . $i] . ', ' . $_POST['l' . $i];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法