2010-05-27 17 views
0

我有一个单一的分层类别数组。数组的索引是CATEGORY_ID像::我们如何才能将单维数组转换为多维的分层?

[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 
    ) 

每个值有其价值parent_category,我有数组中的大约500元,是什么让它的最佳方法。

过程中,我遵循:

krsort类别排列,让所有的孩子类别的开头,然后

function makeHierarchical() { 
    foreach($this->categories as $guid => $category) { 
    if($category['level'] != 1) 
    $this->multilevel_categories[$category['parent_category']][$guid] = $category; 
} 

}

,但是这是行不通的,它只做它为第一级。

有人可以指出我的错误。

+1

另请参见http://stackoverflow.com/questions/2892676#2892821 – Artefacto 2010-05-27 12:24:08

回答

相关问题