Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Drzewo znalezienie gałęzi
atomp3
post
Post #1





Grupa: Zarejestrowani
Postów: 126
Pomógł: 1
Dołączył: 31.03.2006

Ostrzeżenie: (0%)
-----


Witam

Mam taką strukturę drzewa:

1. Jak znaleźć ostatnią gałąź
2. Jak znaleźć gałąź nad nią

Np potrzebuje dodać usun dla poj galezi natomiast nad nia usun wszystkie podlegle.

  1. function createTree($array, $currentParent, $currLevel = 0, $prevLevel = -1) {
  2.  
  3. foreach ($array as $categoryId => $category) {
  4.  
  5. if ($currentParent == $category['parent_id']) {
  6.  
  7. if ($currLevel > $prevLevel) echo " <ul id='browser' class='treeview'> ";
  8.  
  9. if ($currLevel == $prevLevel) echo " </li> ";
  10.  
  11. echo '<li id="'.$categoryId.'"><span>'.$category['name'].'</span>';
  12.  
  13. if ($currLevel > $prevLevel) { $prevLevel = $currLevel; }
  14.  
  15. $currLevel++;
  16.  
  17. $this->createTree ($array, $categoryId, $currLevel, $prevLevel);
  18.  
  19. $currLevel--;
  20. }
  21.  
  22. }
  23.  
  24. if ($currLevel == $prevLevel) echo " </li> </ul> ";
  25.  
  26. }


Dzieki
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 17:11