我有一個單一的分層類別數組。數組的索引是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;
}
}
,但是這是行不通的,它只做它爲第一級。
有人可以指出我的錯誤。
另請參見http://stackoverflow.com/questions/2892676#2892821 – Artefacto 2010-05-27 12:24:08