2013-05-01 41 views
0

我有套輸入字段:控制陣列輸出字段

<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 (
'question_id' => 
    array (
     0 => '6', 
     1 => '6', 
    ), 
'position' => 
    array (
     0 => '50', 
     1 => '60',  
    ), 
'answer' => 
    array (
     0 => 'London', 
     1 => '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]),但數組變得更加複雜。感謝您的時間!

+1

'數據[0] [question_id]'等? – 2013-05-01 20:22:38

+0

這樣做。謝謝! – bazzaretta 2013-05-01 20:32:51

+0

添加了接受的答案。 – 2013-05-01 20:34:17

回答

1
<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" /> 

(每在原來的問題的評論)