My database has 2 columns. the person's ID is repeated 5 times in 1 column and each its paired in another column with a question answer Something like this:
ID Answer
1 A1
1 A4
1 A2
1 A9
1 A3
12 A1
12 A11
12 A12
12 A17
12 A2
What i want to try to do is to merge all the answers into 1 array with its ID something like
array (
[1] => array ( 0 => 'A1', 1 => 'A4', 2 => 'A2', 3 => 'A9', 4 => 'A3'),
[12] => array ( 0 => 'A1', 1 => 'A11', 2 => 'A12', 3 => 'A17', 4 => 'A2')
)
My code is as follows:
foreach ($quiz_answers as $aq => $aa)
{
$array_loop = array( $aa['response_id'] => array( $aa['answer'] ) );
$ss = array_merge_recursive($array_loop, $array_loop);
}
My Problem is that somehow the loop doesnt merge in the desired way and i only get 2 outputs. I am not very good at manipulating arrays and probably i need another function but i am not quite sure what i am missing. I've tried using another variable in array_merge_recursive($anotherVariable, $array_loop);
but this doesnt work either.