dongxinche1264 2017-05-23 08:36
浏览 49

如何用动态形式获得所需的多维数组?

I want to get desired multidimensional array as follows:

array (
  array (abc => 'a', def => 1),
  array (abc => 'b',def => 2)
)

But unable to get idea how to build its form. Help me on this guys.

I tried to build form as follows with expectation to get the above results.

<form method="POST" action="test.php">
<textarea name="test[][abc]"></textarea>
<input type="text" name="test[][def]">
<textarea name="test[][abc]"></textarea>
<input type="text" name="test[][def]">
// the 2nd set of textarea and input was dynamically generated by jQuery
<input type="submit">
</form>

Apologize if earlier questions not completed for you guys to understand.

UPDATED :

After certain modification on HTML I successfully get an array as follows:

Array
(
    [scope] => Array
        (
            [0] => iusd
            [1] => aishsadf
        )

    [qty] => Array
        (
            [0] => 723186
            [1] => 324
        )

)

How to access the value and pair it?

  • 写回答

2条回答 默认 最新

  • doubi3929 2017-05-23 08:44
    关注

    Gather the values in an multidimensional array by giving the input fields a name with [][]. Let the post request post to the same file for testing purposes. Print the values out by creating a nested foreach statement.

    //filename = post.php
    <form action="post.php" method="post">
        <label>field1</label>
        <input type="text" name="array[0][value1]">
        <label>field2</label>
        <input type="text" name="array[1][value2]">
    
        <input type="submit" value="submit">
     </form>
    
     <?php
    
        if(isset($_POST)){
          $array = $_POST['array'];
    
          foreach($array as $key => $array2){
             foreach($array2 as $key => $value){
                echo $value;
             }       
          }
        }
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么