PHP Function - hierarchical tree / list from a flat array
- or -
Post a project like this3092
$$$
- Posted:
- Proposals: 8
- Remote
- #896341
- Awarded
Description
Experience Level: Expert
General information for the website: Blog categories
Num. of web pages/modules: 1
Description of requirements/features: We are working on a blog functionality where people can create their own categories and subcategories.
We are originally working from a flat array - each element of the array contains: category_name, category_id, category_parent_id.
We need to turn that flat array into a tree of indented UL / LI of all the categories with the relevant hierarchy and children. We also want the same to be in a drop down menu. Have a look at the category page in Wordpress for example (on the left is the drop down, on the right the list) that shows the indentation / parent - child relationship.
We are happy for the main function to be some kind of array walker and to have one function to output the list and another for the dropdown (ie 3 functions in total). The flat array has to be manipulated post creation (ie you will be given an array and it has to output as per our requirements, no additional querying of the database)
I have looked up on stack exchange for solutions but what I found wasn't satisfactory (mention of infinite loop or memory issue; or use of variable variables and aliases).
Extra notes:
Num. of web pages/modules: 1
Description of requirements/features: We are working on a blog functionality where people can create their own categories and subcategories.
We are originally working from a flat array - each element of the array contains: category_name, category_id, category_parent_id.
We need to turn that flat array into a tree of indented UL / LI of all the categories with the relevant hierarchy and children. We also want the same to be in a drop down menu. Have a look at the category page in Wordpress for example (on the left is the drop down, on the right the list) that shows the indentation / parent - child relationship.
We are happy for the main function to be some kind of array walker and to have one function to output the list and another for the dropdown (ie 3 functions in total). The flat array has to be manipulated post creation (ie you will be given an array and it has to output as per our requirements, no additional querying of the database)
I have looked up on stack exchange for solutions but what I found wasn't satisfactory (mention of infinite loop or memory issue; or use of variable variables and aliases).
Extra notes:
Keith S.
99% (15)Projects Completed
18
Freelancers worked with
14
Projects awarded
52%
Last project
6 May 2023
United Kingdom
New Proposal
Login to your account and send a proposal now to get this project.
Log inClarification Board Ask a Question
-
There are no clarification messages.
We collect cookies to enable the proper functioning and security of our website, and to enhance your experience. By clicking on 'Accept All Cookies', you consent to the use of these cookies. You can change your 'Cookies Settings' at any time. For more information, please read ourCookie Policy
Cookie Settings
Accept All Cookies