Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Recursive loop from a hierarchical multidimensional array
Goto page Previous  1, 2
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
pedrotester
Smarty Regular


Joined: 06 Jun 2019
Posts: 40

PostPosted: Fri Jun 14, 2019 9:12 pm    Post subject: Reply with quote

That doesn't answer my question, I still have to do twice the same thing. Is it normal? yes or no, no riddle plz
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Jun 14, 2019 9:18 pm    Post subject: Reply with quote

No, it's not the same thing.
If my answer "doesn't answer your question", then google the difference yourself.
Back to top
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Sun Jun 16, 2019 2:40 am    Post subject: Reply with quote

A multi-level parent->child hierarchy of similar structure is the very definition of recursion. (See: fractal)

Technically, you don't need to recurse. You can do the same with a massive amount of repetitive code. But doing that would require you to have an intimate knowledge of the nature of your source data. For example, you know for a fact that you only have, and only will ever have, at most, three generations of relationships with three siblings in each generation.

And if that is your intended structure - three generations - then massive amounts of repeating code would suffice.

The problems start when you need to change some aspect of each sibling. Change massive numbers of instances - or just one that gets recursed (or is a function call).

So, use recursion to construct your hierarchical structure, and use recursion to deconstruct that structure into the required displayable orientation/organization.

This is a general programming (problem-solving) task -- breaking a large pattern into manageable, repeatable, smaller and identical patterns.
Back to top
View user's profile Send private message
pedrotester
Smarty Regular


Joined: 06 Jun 2019
Posts: 40

PostPosted: Mon Jun 17, 2019 7:33 pm    Post subject: Reply with quote

thank you for explanation!
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP