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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:34:16+00:00 2026-06-16T14:34:16+00:00

Just building on top of my previous question here: Rewriting a JSON string –

  • 0

Just building on top of my previous question here:

Rewriting a JSON string – grouping keys by value into a new array?

I am wondering how do I traverse the array given and resort it so that the output comes out something like this:

[{
"Name": "Title 1",
"Date": "2012-12-05",
"rows": [
    {
        "Subtitle": "Subtitle 1",
        "Count1": 566,
        "Count2": 105
    },
    {
        "Subtitle": "Subtitle 2",
        "Count1": 76,
        "Count2": 15
    }
    ]
}, 
{
"Name": "Title 2",
"Date": "2012-12-06",
"rows": [
    {
        "Count1": 66,
        "Count2": 5
    }...

where the original json array is grouped by “Name” column, and then sorted into multi-level structure like this (parent/multiple child json structure for properly building menu in our application)?

The original json data looks like this:

[{
"Name": "Title 1",
"Subtitle": "Subtitle 1",
"Count1": 556,
"Count2": 5,
"Date": "2012-12-05"
}, {
"Name": "Title 1",
"Subtitle": "Subtitle 2",
"Count1": 10,
"Count2": 100,
"Date": "2012-12-05"
}, {
"Name": "Title 3",
"Subtitle": "Subtitle 3",
"Count1": 798,
"Count2": 11,
"Date": "2012-12-04"
}...

and obviously I am looking for a solution in PHP, as I will read in the json data, process it and spit it out reformatted.

  • 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-16T14:34:17+00:00Added an answer on June 16, 2026 at 2:34 pm

    Assuming associative arrays and sorting output by name:

    $output = array();
    
    for ($data as $row) {
    
        if (!isset($output[$row['Name']])) {
            $output[$row['Name']] = array(
                'Name' => $row['Name'],
                'Date' => $row['Date'],
                'rows' => array()
            );
        }
    
        $output[$row['Name']]['rows'][] = array(
            'Subtitle' => $row['Subtitle'],
            'Count 1'  => $row['Count 1'],
            'Count 2'  => $row['Count 2'] 
        );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very new to MVC, and just building my first site, using NerdDinner as
I am fairly new to Flotr2 and I have just been building some simple
I'm just getting into using REST and have started building my first app following
I'm building my first ever jQuery plugin (it's just a simple experiment). Here's what
im just building a very simple event based proxy monitor top disable the proxy
I'm building a JSON API on top of devise in order to be able
We've just started building our own push notification system (due to client's requirement) for
Just getting started building an app using the v6 of the facebook c# sdk
I am building a waterfall view just like pinterest. Now I have to explicitly
I am building simple notificiation system and I just wanted to know what is

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.