如何通过POST发送几个数组?

时间:2014-12-12 15:18:01

标签: php arrays post

因此,例如,我们有一份订单,其中包含一系列产品,如输入表:

  • Product_id | Product_Quantity | Product_Sum
  • 1 .................. 100 ........................ 1000
  • 2 .................. 200 ........................ 2000
  • 3 .................. 300 ........................ 3000

还有一些其他输入,例如shipping_cost或customer_name。

我们如何通过POST发送整个订单表格如果我们需要将服务器上的购物车作为数组阵列捕获?

所以另一方面我们应该看到:

  • $ _ POST [shipping_cost] = ...
  • $ _ POST [[1,100,1000],[2,200,200],[3,300,3000]]
  • $ _ POST [costomer_name] = ...

也许你会提供一些收集和处理这张桌子的方法吗?

1 个答案:

答案 0 :(得分:1)

POST不包含“数组”。它只包含字符串。如果要发送数组,则必须以某种方式将它们序列化/编码为普通字符串,发送该字符串,然后解码/反序列化为数组。

有PHP的数组命名hack:

<input type="text" name="foo[bar][baz]" value="qux" />

将被视为等同于

$_POST = array(
  'foo' => array (
     'baz' => 'qux'
  )
)

由PHP。

相关问题