我想从post获取一些输入值并将它们存储在一个数组中.这是我的输入元素,它们是可重复的字段:
<input type="text" class="form-control" id="exampleInputPassword1" name="itemquantity[]" />
<input type="text" class="form-control gettitles" id="exampleInputPassword1" name="buyproduct[]" />
<input type="text" class="form-control gettitles" id="exampleInputPassword1" name="freeproduct[]" />
Run Code Online (Sandbox Code Playgroud)
当我提交表单和print_r时,我得到以下内容(字段已重复):
Array ( [itemquantity] => Array (
[0] => 1
[1] => 4
)
[buyproduct] => Array (
[0] => 2
[1] => 5
)
[freeproduct] => Array (
[0] => 3
[1] => 6
)
Run Code Online (Sandbox Code Playgroud)
我如何按重复提交的方式对它们进行分组?
所以例如我希望输出像这样:
Array(
Array [0](
[itemquantity] => 1
[buyquantity] => 2
[freeproduct] => 3
)
Array [1](
[itemquantity] => 4
[buyquantity] => 5
[freeproduct] => 6
)
)
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激,谢谢!
小智 5
您可以在PHP中更轻松地使用它:
<input type="text" class="form-control" id="exampleInputPassword1" name="item1[itemquantity]" />
<input type="text" class="form-control gettitles" id="exampleInputPassword1" name="item1[buyproduct]" />
<input type="text" class="form-control gettitles" id="exampleInputPassword1" name="item1[freeproduct]" />
<input type="text" class="form-control" id="exampleInputPassword1" name="item2[itemquantity]" />
<input type="text" class="form-control gettitles" id="exampleInputPassword1" name="item2[buyproduct]" />
<input type="text" class="form-control gettitles" id="exampleInputPassword1" name="item2[freeproduct]" />
Run Code Online (Sandbox Code Playgroud)
这将成为PHP post变量:
Array(
Array [item1](
[itemquantity] => 1
[buyquantity] => 2
[freeproduct] => 3
)
Array [item2](
[itemquantity] => 4
[buyquantity] => 5
[freeproduct] => 6
)
)
Run Code Online (Sandbox Code Playgroud)