Bonjour,
j'ai un tableau sous cette forme:
uid parent_uid
5 0
4 0
10 4
11 4
12 10
et je souhaiterai obtenir un tableau associatif comme suit:
("5" => array(), "4" => array("10" => array("12" => array), "11" => array()))
j'ai le code suivant:
Mais je n'arrive pas a avoir les sous tableaux!
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 //init $tabs = array(); $parent_tab = array(); foreach <line> { $parent_tab[<uid>] = <parent_uid>; $tabs[<uid>] = array(); } $sorted = array(); foreach($parent_tab as $uid => $parent_id) { if ($parent_id == 0) { $h_sorted[$uid] = &$tabs[$uid]; } else { $tabs[$parent_id][$uid] = &$tabs[$uid]; } }
merci de votre aide
Partager