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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:54:46+00:00 2026-06-11T00:54:46+00:00

So I have my query, its returning results as expect all is swell, except

  • 0

So I have my query, its returning results as expect all is swell, except today my designer through in a wrench. Which seems to be throwing me off my game a bit, maybe its cause Im to tired who knows, anyway..

I am to create a 3 tier array

primary category, sub category (which can have multiples per primary), and the item list per sub category which could be 1 to 100 items.

I’ve tried foreach, while, for loops. All typically starting with $final = array(); then the loop below that.

trying to build arrays like:

$final[$row['primary]][$row['sub']][] = $row['item]
$final[$row['primary]][$row['sub']] = $row['item]

I’ve tried defining them each as there own array to use array_push() on. And various other tactics and I am failing horribly. I need a fresh minded person to help me out here. From what type of loop would best suit my need to how I can construct my array(s) to build out according to plan.

The Desired outcome would be

array(
   primary = array
             (
                sub = array
                      (
                        itemA,
                        itemB,
                        itemC
                      ),
                sub = array
                      (
                        itemA,
                        itemB,
                        itemC
                      ),
             ),
   primary = array
             (
                sub = array
                      (
                        itemA,
                        itemB,
                        itemC
                      ),
                sub = array
                      (
                        itemA,
                        itemB,
                        itemC
                      ),
             ),
)
  • 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-11T00:54:47+00:00Added an answer on June 11, 2026 at 12:54 am

    Something like this during treatment of your request :

    if (!array_key_exists($row['primary'], $final)) {
        $final[$row['primary']] = array();
    }
    if (!array_key_exists($row['sub'], $final[$row['primary']])) {
        $final[$row['primary']][$row['sub']] = array();
    }
    $final[$row['primary']][$row['sub']][] = $row['item'];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this query. It matches anything which has South in its name. But
I have the following query which gives me the right results. But it's super
I have a LINQ query which is attempting to get all of the distinct
I have a query that's returning a LOT of results and my code is
I have a query returning large XML, its size can reach 1GB in extreme
I have the following LINQ query. The problem is it's returning 13k results when
I have an odd XML document that I have to query. Its from the
I have a query which contains a select statement in it's where clause. My
I have query table copyQuery which has Soil Condition has one of the columns,
I currently have the following MySQL query, which executes fine without any errors: SELECT

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.