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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:44:22+00:00 2026-05-15T23:44:22+00:00

I have a tree-like object structure that consists of two types of objects: object

  • 0

I have a tree-like object structure that consists of two types of objects:

  1. object of class Category
  2. object of class CategoryLink

The structure is the following:

The whole story begins with an array of Categories that have no parent
Each Category has a few unimportant properties and a few important:
$parent – containing an id of a parent Category,
$children – containin an array of childern Categories (may be empty if the category has no childern of course).
$links – containing an array of CategoryLinks (also possibly empty)

While __constructing a Category, I look for existing child Categories and CategoryLinks, and if there are some, I create their instances and add them to $children and $links, so this procedure repeats for the children and their children and so on, until a category with no children is reached.

So what this procedure does is that it basically creates a tree of Categories and their Links. This goes well enough, until I want to output this tree structure (using Smarty), and I’m not quite sure how to iterate over it the proper way. Desired output is something like this

Parent1 -its unimportant properties
    -Child1 - its unimportant properties
    -Child2 -...
        -Child2's Child1
        -Child2's Child2
    -Child3
Parent2
    -Child1
        -Child1's Child1
    -Child2
Parent3
...

I’m not sure if its better to iterate over it in PHP and convert it to a multi-dimensional array and iterate over it in Smarty, or do it all the way in Smarty.

*note that I didn’t mention objects of class CategoryLink, as the Category may contain only one-dimensional array of them, so iterating over them is rather easy, I’m just not sure how to iterate over the whole structure.

What is the best | right way to do this?

  • 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-15T23:44:22+00:00Added an answer on May 15, 2026 at 11:44 pm

    Trees lend themselves to very elegant recursive operations. In this case you’re describing a depth-first pre-order traversal. The Wikipedia page might be useful. As for the rest, pushing it into a multi-dimensional array sounds sensible enough if that’s the easiest way for you to display it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have objects in a tree structure, I would like to aggregate status information
I have tree like following example, where every leaf is object. [1] |--[2] |
I have an entity that is actually tree object structure (defining only relevant properties
I have a object structure like this: public class Entity { IList<Relationship> Relationships{get;set;} }
I have a tree structure in memory that I would like to render in
I have the following class which recurs on itself to form a tree-like data
I have a tree-like object, managed by Hibernate. The object has a list of
I am trying to have a javascript object tree behave like a php associative
I have a tree of objects in my viewModel. The objects are something like
We have a table with tree structure like this: Id Desc ParentID === 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.