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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:17:14+00:00 2026-05-28T03:17:14+00:00

I have this data (columns are depth, name, value, the order is correct): 0,

  • 0

I have this data (columns are depth, name, value, the order is correct):

0, id,    12
0, name,  Name
0, pages,
1, 0,     Page 1
1, 1,     Page 2
1, 2,     Page 3
0, items,
1, 0,
2, id,    4
2, title, Example Items

And I’m trying to produce an array structure like this from it:

Array
(
    [id] => 12
    [name] => Name
    [pages] => Array
        (
            [0] => Page 1
            [1] => Page 1
            [2] => Page 1
        )
    [items] => Array
        (
            [0] => Array
                (
                    [id] => 4
                    [title] => Example Item
                )
        )
)

Every attempt I’ve tried so far has failed, I just cant seem to get my head round the logic. Any help would be appreciated. Thanks.

  • 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-28T03:17:14+00:00Added an answer on May 28, 2026 at 3:17 am

    You can accomplish this with a bit of reference trickery. If you have your CSV input converted into a list like:

    $in = array_map("str_getcsv", explode("\n", $table));
    

    Then you can traverse it like:

    $data = array();
    
    foreach ($in as $row) {
        list ($depth, $key, $value) = $row;
    
        $r = & $data;  // start from base array, then submerge $n last keys
        while ($depth--) { end($r); $r = & $r[key($r)]; }
    
        $r[$key] = $value;
    }
    

    At least works for your example:

    Array
    (
        [id] => 12
        [name] => Name
        [pages] => Array
            (
                [0] => Page 1
                [1] => Page 2
                [2] => Page 3
            )
    
        [items] => Array
            (
                [0] => Array
                    (
                        [id] => 4
                        [title] => Example Items
                    )
    
            )
    
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a set of data, with columns x and y. This set contains
I have this code: in = [5 columns of data-points]; out = [1 column
I have a table which has columns of data that contain status. Two example
I have this table view where I write some data in different columns. I
I have a query like this: SELECT TABLE_NAME, COLUMN_NAME, IS_NULLABLE, DATA_TYPE FROM MY_DB.INFORMATION_SCHEMA.COLUMNS WHERE
I'm having a small problem. I have this grid with a column: <data:DataGrid ColumnHeaderStyle={StaticResource
I have a varchar column that has data like this top<somenumber> so the word
I have an xml column which contain data like this: <AuthorList CompleteYN=Y> <Author ValidYN=Y>
If I have a table column with data and create an index on this
I have some data that looks something like this... +----------+----------+----------+ | Column 1 |

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.