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

  • SEARCH
  • Home
  • 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 7541627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:56:35+00:00 2026-05-30T07:56:35+00:00

I am having this array. Last few hours I have been trying to loop

  • 0

I am having this array. Last few hours I have been trying to loop through and make another which will arrange the question in respective subjects.

[23] => Array
        (
            [right] => A list of station and network addresses with corresponding gateway IP address.
            [id] => 23
            [level] => Professional
            [subject] => Array
                (
                    [0] => Array
                        (
                        [tid] => 1
                    )

                [1] => Array
                    (
                        [tid] => 6
                    )

            )

        [question] => What is an IP routing table?
        [answer] => A list of host names and corresponding IP addresses.
        [correct] => 0
    )

[22] => Array
    (
        [right] => Session hijacking attack
        [id] => 22
        [level] => Professional
        [subject] => Array
            (
                [0] => Array
                    (
                        [tid] => 1
                    )

                [1] => Array
                    (
                        [tid] => 6
                    )

            )

        [question] => How would an IP spoofing attack be best classified?
        [answer] => Session hijacking attack
        [correct] => 1
    )

[21] => Array
    (
        [right] => Repeater
        [id] => 21
        [level] => Intermediate
        [subject] => Array
            (
                [0] => Array
                    (
                        [tid] => 1
                    )

                [1] => Array
                    (
                        [tid] => 6
                    )

            )

I want to make something like below.

array ( [tid1] => array (
                            [0] array (  [question] => something )
                            [1] array (  [question] => somethingelse )
                           )
         [tid2] => array (
                            [0] array (  [question] => something )
                            [1] array (  [question] => somethingelse )
                           )

But I’m not able to do it. What is the best way to do this?

  • 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-05-30T07:56:36+00:00Added an answer on May 30, 2026 at 7:56 am

    Assuming that your data is in an array called $data and that since each question can have multiple subjects, each question may appear multiple times in the final array:

    $final = array();
    foreach($data as $datum){
        $subjects = $datum['subject'];
        foreach($subjects as $subject){
            $tid = 'tid' . $subject['tid'];
            $final[$tid][] = array('question' => $datum['question']);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been having this issue in iterating through an array of keys and
Having been playing around with C# the last few days and trying to take
I am been having trouble counting the number of objects in this array in
I have a loop in my script, which iterates over an array - myArray
I am having trouble with this association. I need to get an array of
Having this route: map.foo 'foo/*path', :controller => 'foo', :action => 'index' I have the
After having this question answered through a link to an external site , I
I am having issues the last number in this code is not being sorted.
Hopefully this will be the last question I need to ask about this..lol.. I
Let's say I have this collection: val a = Array(Array(1,2,3,4,5),Array(4,5),Array(5),Array(1,2,6,7,8)) Is there a way

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.