dsjws44266 2016-06-03 15:01
浏览 139
已采纳

如何将多个数组合并为一个?

The problem comes when I am echoing more than one order on a page and submitting it. This is my form:

<input name="checkOrder['.($row['ord_no']).'][ord_no]" value="'.($row['ord_no']).'" type="checkbox" class="checkOrder" id="checkOrder">
      <input type="hidden" name="checkOrder['.($row['ord_no']).'][item_seq_no]" value="'.$line_number.'" />
      <input type="hidden" name="checkOrder['.($row['ord_no']).'][item_no]" value="'.$item_number.'" /> 
      <input type="hidden" name="checkOrder['.($row['ord_no']).'][item_desc_1]" value="'.$item_description.'" /></input>

Right now my ouput is this:

Array ( [ord_no] => 1000007 [item_seq_no] => 1 [item_no] => 001 [item_desc_1] => item1 ) 
    Array ( [ord_no] => 1000008 [item_seq_no] => 1 [item_no] => 002 [item_desc_1] => item2 ) 
    Array ( [ord_no] => 1000000 [item_seq_no] => 1 [item_no] => 003 [item_desc_1] => item3 ) 
    Array ( [ord_no] => 1000001 [item_seq_no] => 1 [item_no] => 001 [item_desc_1] => item1 )

I would prefer this:

[checkOrder] => Array
(
        [ord_no] => 1000007
        (
            [item_seq_no] => 1 [item_no] => 001 [item_desc_1] => item1
        )
        [ord_no] => 1000008
        (
            [item_seq_no] => 1 [item_no] => 002 [item_desc_1] => item2
        )
        [ord_no] => 1000000
        (
            [item_seq_no] => 1 [item_no] => 003 [item_desc_1] => item3
        )
        [ord_no] => 1000001
        (
        [item_seq_no] => 1 [item_no] => 001 [item_desc_1] => item1
        )
)

So how do I change my form to create one big array rather than multiple or am I not thinking about this correctly. Right now I am inserting all of these that are checked into a table inside a foreach loop. Then sending one email outside my foreach. It is only inserting the first array order # into the email. When I actually need everyone that was checked. I believe with this other array I have in mind it will fix my problem. If you want more info please let me know.

  • 写回答

1条回答 默认 最新

  • doushi8187 2016-06-03 15:28
    关注

    Change your form to:

      <input name="checkOrder['.($row['ord_no']).'][checked]" value="" type="checkbox" class="checkOrder" id="checkOrder">
      <input type="hidden" name="checkOrder['.($row['ord_no']).'][ord_no]" value="'.($row['ord_no']).'" />
      <input type="hidden" name="checkOrder['.($row['ord_no']).'][item_seq_no]" value="'.$line_number.'" />
      <input type="hidden" name="checkOrder['.($row['ord_no']).'][item_no]" value="'.$item_number.'" /> 
      <input type="hidden" name="checkOrder['.($row['ord_no']).'][item_desc_1]" value="'.$item_description.'" /></input>
    

    if you now var_dump($_POST); you got:

    [checkOrder] => Array
    (
            [1000007] => Array
            (
              [ord_no] => 1000007, [item_seq_no] => 1, [item_no] => 001, [item_desc_1] => item1, [checked]='on'
            )
            [1000008] => Array
            (
              [ord_no] => 1000008, [item_seq_no] => 1, [item_no] => 002, [item_desc_1] => item2, [checked]='on'
            )
            [1000000] => Array
            (
              [ord_no] => 100000, [item_seq_no] => 1, [item_no] => 003,[item_desc_1] => item3, [checked]='on'
            )
            [1000001] => Array
            (
              [ord_no] => 1000001, [item_seq_no] => 1, [item_no] => 001, [item_desc_1] => item1, [checked]='on'
            )
    )
    

    [checked]='on' is only there if you checked that in the Form.

    Hope that helps.

    I need to save just the order numbers outside the foreach

    Then use array_keys($_POST['checkOrder'])and you got the ids.

    But it thing you should use instead of

    <input name="checkOrder['.($row['ord_no']).'][checked]" value="" type="checkbox" class="checkOrder" id="checkOrder">

    this

    <input name="checkedOrders[]" value="'.($row['ord_no'].'" type="checkbox" class="checkOrder" id="checkOrder">

    And then in $_POST['checkedOrders'] are all the ids that where checked in the form.

    The rest will be still the same.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥15 关于超局变量获取查询的问题
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集
  • ¥15 在启动roslaunch时出现如下问题
  • ¥15 汇编语言实现加减法计算器的功能
  • ¥20 关于多单片机模块化的一些问题