How can we make a single dimension array to multidimensional Hierarchical ?
Posted
by Chetan sharma
on Stack Overflow
See other posts from Stack Overflow
or by Chetan sharma
Published on 2010-05-27T12:11:09Z
Indexed on
2010/05/27
12:21 UTC
Read the original article
Hit count: 226
I have an single array of Hierarchical categories. Index of the array is the category_id like::
[8846] => Array
(
[category_id] => 8846
[title] => Tsting two
[description] => Tsting two
[subtype] => categories
[type] => object
[level] => 2
[parent_category] => 8841
[tags] => new
[name] => Tsting two
)
each value has its parent_category value, I have around 500 elements in the array, what is the best way to make it.
Process i followed:
krsort categories array, so that all the child categories are at the beginning, then
function makeHierarchical() {
foreach($this->categories as $guid => $category) {
if($category['level'] != 1)
$this->multilevel_categories[$category['parent_category']][$guid] = $category;
}
}
but this is not working, it does it only for first level.
Can someone point out me the error.
© Stack Overflow or respective owner