douxigai8757 2015-04-29 10:52
浏览 35
已采纳

获取其他PHP var的PHP var

I know the title is not describing the problem very well, so I explain here: I have multiple $_POST with similar names, like question1,question2,question3...

I have a for loop with $i. i want to get this vars ($question1, $question2), in help with $i. For example:

$question.$i = $_POST['question' . $i];

I want to do it because the number of questions is variable, so I have a button that add questions and answers to the page and then you submit it.

  • 写回答

3条回答 默认 最新

  • drdyf42880 2015-04-29 10:54
    关注

    First, you need to make explicitly $question an array. Then you build your $_POST index by concatenating the string and $i with a ..

    So, before the loop:

    $question = array();
    

    and in the loop:

    $question[$i] = $_POST['question'.$i];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图