Linked Questions
25 questions linked to/from create array tree from array list
110
votes
11
answers
77k
views
Convert a series of parent-child relationships into a hierarchical tree?
I have a bunch of name-parentname pairs, that I'd like to turn into as few heirarchical tree structures as possible. So for example, these could be the pairings:
Child : Parent
H : G
F : G
...
0
votes
2
answers
258
views
PHP parent/child iteration in single-dimension array [duplicate]
I am at a little bit of a loss as to how to approach this, I suspect foreach is not the right answer, and I am aware of the existence of array_walk() and RecursiveArrayIterator, but I have no real-...
-1
votes
1
answer
275
views
How to move an array into another? [duplicate]
I have a multidimensional associative array "$nav_menus" looks like this:
Array
(
[0] => Array
(
[id] => 1
[menu_name] => Media
[parent_id] => 0
[...
0
votes
1
answer
44
views
how to make php array tree? [duplicate]
There is the following array.
$arrTmp = array();
$arrTmp = array(
array('id' => 206,
'BoardName' => 'Schedule',
'pid' => 196),
array('id' => 145,
'BoardName' => '...
0
votes
0
answers
26
views
How to group an array by its parent_id? (php / laravel) [duplicate]
I'm currently assigned to task in which I will need to group raw array data. The data is very simple and it has root_id to determine the parent of the element. The task is to group it dynamically ...
55
votes
14
answers
75k
views
Build a tree from a flat array in PHP [duplicate]
I've looked around the internet and haven't quite found what I'm looking for. I have a flat array with each element containing an 'id' and a 'parent_id'. Each element will only have ONE parent, but ...
5
votes
2
answers
1k
views
Algorithm for creating multi-dimensional array
I'm using PHP and I need help with a seemingly simple task with an array.
This is my example array:
$arr = array(
0 => NULL,
1 => NULL,
2 => NULL,
3 => NULL,
8 =&...
2
votes
1
answer
3k
views
create json data for tree structure data with php array using recursion function
I have category table:
CategoryID CategoryName ParentID
1 Root Null
2 News 1
3 Horoscope 1
4 Sports ...
-3
votes
5
answers
2k
views
Create a tree array PHP
I have an array:
$data_array = array(
array('id'=> 1 , 'parent_id' => 1 , 'name'=>'Air Vehicles' ),
array('id'=> 2 , 'parent_id' => 2 , 'name'=>'Land Vehicles' ),
...
0
votes
1
answer
2k
views
How to group array by parent id
Here is my array output
Array
(
[1] => Array
(
[id] => 1
[name] => Category A
[parent] => 0
)
[2] => Array
(
...
0
votes
1
answer
1k
views
How to construct a Database for this kind of Organizational Chart [closed]
So I am planning to create a dynamic organizational chart, can anyone give me a hint on how can I design my database? Org chart is something like image on the link below. Sorry for my bad drawing ...
1
vote
1
answer
380
views
How do I add extra space or dashed symbol to select option?
I want to make a select tree for my category. Here is for unordered list.
function generate_menu($parent, $menu_array = null)
{
$has_childs = false;
foreach ($menu_array as $key => $value) ...
0
votes
1
answer
1k
views
Parse spreadsheet into PHP array and return a nested MLM-like table with parent child relationships
I am currently working on a project that requires me to take an uploaded spreadsheet file (XLSX, XLS, etc), place it into an array, then based off of the parent child relationship, build an HTML table ...
0
votes
2
answers
685
views
Puzzle: How to organize a dynamic hierarchical categories menu
I'm trying to develop a hierarchical menu in my e-commerce website in which my categories are dynamically shown in order to add more categories without having to touch the code.
So I've organized my ...
1
vote
1
answer
498
views
Build tree with branches in php
I have $categories variable returns the following JSON data. I'd like to build a Tree->Branches in Php from this variable. Any idea?
+Public
- Electonics
.....- Computer
........+ iPad-Tablets
.....+...