Php 使用输入字段控制数组输出
我有多组输入字段:Php 使用输入字段控制数组输出,php,html,Php,Html,我有多组输入字段: <input type="text" name="data[question_id][]" value="6" /> <input type="text" name="data[position][]" value="50" /> <input type="text" name="data[answer][]" value="London" /> <input type="text" name="data[question_id]
<input type="text" name="data[question_id][]" value="6" />
<input type="text" name="data[position][]" value="50" />
<input type="text" name="data[answer][]" value="London" />
<input type="text" name="data[question_id][]" value="6" />
<input type="text" name="data[position][]" value="60" />
<input type="text" name="data[answer][]" value="New York" />
但是,我需要数组采用以下格式:
array (
0 =>
array (
'question_id' => '6',
'position' => '50',
'answer' => 'London',
),
1 =>
array (
'question_id' => '7',
'position' => '60',
'answer' => 'New York',
),
)
我尝试将括号放在数据(data[][question_id])之后,但数组变得更加复杂。谢谢你抽出时间
<input type="text" name="data[0][question_id]" value="6" />
<input type="text" name="data[0][position]" value="50" />
<input type="text" name="data[0][answer]" value="London" />
<input type="text" name="data[1][question_id]" value="6" />
<input type="text" name="data[1][position]" value="60" />
<input type="text" name="data[1][answer]" value="New York" />
(根据原始问题中的注释)
data[0][question\u id]
etc?添加了接受答案。
<input type="text" name="data[0][question_id]" value="6" />
<input type="text" name="data[0][position]" value="50" />
<input type="text" name="data[0][answer]" value="London" />
<input type="text" name="data[1][question_id]" value="6" />
<input type="text" name="data[1][position]" value="60" />
<input type="text" name="data[1][answer]" value="New York" />