Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9271579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:39:17+00:00 2026-06-18T15:39:17+00:00

My database has 2 columns. the person’s ID is repeated 5 times in 1

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T15:39:19+00:00Added an answer on June 18, 2026 at 3:39 pm

    Simply change your foreach loop to construct the resulting array how you desire.

    foreach ($quiz_answers as $aa) {
        $ss[$aa['response_id']][] = $aa['answer'];
    }
    

    This gives an $ss array as you want:

    array(
        1  => array('A1', 'A4', 'A2', 'A9', 'A3'),
        12 => array('A1', 'A11', 'A12', 'A17', 'A2'),
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using http://keith-wood.name/countdown.html . Each 'Event' table in my database has a 'date' column.
I have a Rails model called Person which has database table columns for first_name
One of the tables in my database has three columns. They are dt_id (PK),
I have a database that has the following columns: ------------------- id|domain|hit_count ------------------- And I
Given a database that has numerous repeating columns used for auditing and versioning, what
I have a database with many tables and one particular table has columns: name
I have a rather large database that has alot of decimal columns in alot
Currently I have a database of Courses, and it has 6 columns: class Course(models.Model):
Okay, so. I've got a database which has a column of timestamps. The start
I have an SQL Server 2008 database with a table that has a column

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.