0

I have sets of input fields:

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

Here's my output:

array (
'question_id' => 
    array (
        0 => '6',
        1 => '6',
    ),
'position' => 
    array (
        0 => '50',
        1 => '60',      
    ),
'answer' => 
    array (
        0 => 'London',
        1 => 'New York',
    ),
)

However, I need the array to be in the following format:

array (
0 =>
    array (
        'question_id' => '6',
        'position' => '50',
        'answer' => 'London',
    ),
1 =>
    array (
        'question_id' => '7',
        'position' => '60',
        'answer' => 'New York',
    ),
)

I tried placing the brackets after data (data[][question_id]), but the array becomes even more convoluted. Thank you for your time!

2
  • 1
    data[0][question_id] etc? Commented May 1, 2013 at 20:22
  • Added an answer for acceptance. Commented May 1, 2013 at 20:34

1 Answer 1

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

(per the comments in the original question)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.