Jump to content

Recommended Posts

Hi.
I would like to build a complex data structure in a foreach bucle and return it after

foreach ($array as $row) {
  // Here we get groupname and item_info for each row.
}

I want an array of groups(stdClass).

Each group has info, and a list of items(stdClass).

array(
  stdClass Group_1 (
    info
    list = array (
      stdClass item_1 (
        info
      )
      stdClass item_2 (..)
      ...
    )
  )
  ...
  stdClass Group_n (...)
)

Any help to build this would be apreciated. Thank you.

Hehe, sorry about that. Please let me explain again:

 

We have an array of stdClass elements: 

array(element_1, element_2, ..., element_n)

Each element is like:

element_k : {order: int, name: "name", group_name: "name", group_order: int}

Ok. Now I want to build an array / stdClass based data structure like followes: 

array:[group_1 : {name : "name",
                  order : int,
                  items : [ item_1 : {name : "name", order : int },
                            ...
                            item_n : {...}
                          ]
                  },
       ...
       group_n : {...}
      ]

I was thinking doing it in a loop, but maybe there is a better way.

Thank you very much for your time.

Regards

Patrick

Edited by patrickhertling
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.