Hiérarchisation d'objet dans un tableau
salut à tous...
voila, j'ai un petit pb ... de hyerarchisation de catégories ...
je récupère un résultat sql genre ça
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| array
0 =>
object(stdClass)[12]
public 'idCategorie' => string '4' (length=1)
public 'nomCategorie' => string 'Cat 1' (length=5)
public 'parent' => null
1 =>
object(stdClass)[11]
public 'idCategorie' => string '5' (length=1)
public 'nomCategorie' => string 'cat 2' (length=5)
public 'parent' => null
2 =>
object(stdClass)[10]
public 'idCategorie' => string '6' (length=1)
public 'nomCategorie' => string 'cat 1.1' (length=7)
public 'parent' => string '4' (length=1)
3 =>
object(stdClass)[1]
public 'idCategorie' => string '7' (length=1)
public 'nomCategorie' => string 'cat 1.2' (length=7)
public 'parent' => string '4' (length=1)
4 =>
object(stdClass)[14]
public 'idCategorie' => string '8' (length=1)
public 'nomCategorie' => string 'cat 1.1.1' (length=9)
public 'parent' => string '6' (length=1) |
donc dans chaque catégorie j'ai un id et l'id du parent si besoin...
j'aimerai passer tout ça dans une fonction php qui me retourne un tableau sous la forme
nom---- | id ---- | depth|
cat 1 ---| 4 -----| 0
cat1.1-- | 6 -----| 1
cat 1.1.1 | 8 ----| 2
cat1.2-- | 9 -----| 1
cat2 ----| 5 -----| 0
bien sur dans cet ordre puisque je dois l'afficher ainsi ...
vous avez une idée de comment faire ça ? parce que là je sèche :(
merci d'avance
++