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 6629889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:19:32+00:00 2026-05-25T22:19:32+00:00

I currently have the following array: Array ( [group] => Array { [5] =>

  • 0

I currently have the following array:

Array
(
    [group] => Array
        {
            [5] => group1-title
            [6] => group2-title
        }
    [treatment] => Array
        (
            [5] => Array
                (
                    [16] => Array
                        (
                            [title] => title1
                            [description] => description1
                            [price] => price1
                        )

                    [17] => Array
                        (
                            [title] => title2
                            [description] => description2
                            [price] => price2
                        )
            [6] => Array
                (

                    [21] => Array
                        (
                            [title] => title3
                            [description] => description3
                            [price] => price3
                        )
                }
        }
}

(In reality the array data is large so it has been cropped to give an example above)

What I am attempting to do is run a foreach loop over the array to enable to me group the data in a pricing table separate by their groups (the array keys [5] and [6])

The end result I am aiming for is the following:

Group1-Title


Title 1 | Desc | Price
Title 2 | Desc | Price


Group2-Title


Title 3 | Desc | Price


I have attempted so far with a foreach loop with an inner foreach loop. That pulls the details and echos out fine – however I can’t figure out how to successfully group the data during the foreach loop.

  • 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-25T22:19:33+00:00Added an answer on May 25, 2026 at 10:19 pm

    Here’s one way to go about it. Grab the first array item and use that for the titles. Then loop through the rest of your array using the keys from the first item to display the results. Obviously my display code is quick and dirty, but this should get you started.

    foreach($your_array['group'] as $iGroupId => $sTitle) {
        echo 'Group: ' . $sTitle . "\n";
        foreach($your_array['treatment'][$iGroupId] as $aGroup) {
            echo implode('|', $aGroup); . "\n"
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have the following objects persisting successfully: Person first name, etc. Exams title,
I have the following two tables activity(activity_id, title, description, group_id) statistic(statistic_id, activity_id, date, user_id,
I currently have the following javascript array: var stuffs = ['a', 'b']; I pass
I have the following array, it is currently created sorted by entity_count (outputted by
I currently have the following array, Array (1) 0 => Array (5) productid =>
I currently have the following lines of code in a script: set -A ARRAY
I currently have the following array in a Java program, byte[] data = new
I currently have the following CSS for my 4 columns which might grow to
I currently have the following row in my table: course_data: user_id days <-- This
I currently have the following MySQL statement to replace the HTML entity for a

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.