az wstyd pisac, ale sil tez brak
mam tako oto tablice:
(
(
(
[name] => Artykuły
[url] => content/
[main] => TRUE
)
(
[name] => Nowy artykuł
[parentModuleName] => content
[url] => content/new
)
(
[name] => Kategorie
[parentModuleName] => content
[main] => TRUE
[url] => content_category/
)
)
[content_category
] => Array (
(
[name] => Nowa kategoria
[parentModuleName] => content_category
[url] => content_category/new
)
)
i teraz cchcialbym z niej utworzyc ladne drzewko.
tylko chyba czegos jeszcze mi brakuje bo za diabla nie moge przypisac "Nowa kategoria" pod "Kategorie".
Ktos spojrzy i mi podpowie ?
odpisze
doszedlem krok dalej.
Teraz zatrzymalem sie na takiej tablicy:
Array
(
[content] => Array
(
[name] => Artykuły
[url] => content/
[main] => TRUE
[parentModuleName] =>
[id] => 0
[module] => content
[childs] => Array
(
[0] => Array
(
[name] => Nowy artykuł
[parentModuleName] => content
[url] => content/new
[id] => 1
[module] => content
)
[1] => Array
(
[name] => Kategorie
[parentModuleName] => content
[main] => TRUE
[url] => content_category/
[id] => 2
[module] => content_category
)
)
)
[content_category] => Array
(
[childs] => Array
(
[0] => Array
(
[name] => Nowa kategoria
[parentModuleName] => content_category
[url] => content_category/new
[id] => 3
[module] => content_category
)
)
)
)
takim kodem:
public function sortArray($array, $parent = null)
{
foreach($array as $link)
{
if($link['parentModuleName'] == null)
$result[$link['module']] = $link;
else
{
$lp = $array[$link['id']]['parentModuleName'];
$result[$lp]['childs'][] = $link;
//$this->sortArray($array, $link['parentModuleName']);
}
}
return $result;
}
teraz chcialem podpiac rekurencje ale cos nie bardzo wychodzi
prosze o pomoc