0

I have an array that looks like this

Array
(
 [0] => Array
 (
   [id] => 1
   [label] => computer
   [parent] => 0
   [child] => Array
   (
     [0] => Array
     (
       [id] => 2
       [label] => portable
       [parent] => 1
       [child] => Array
       (
       )
     )
     [1] => Array
     (
       [id] => 3
       [label] => fixe
       [parent] => 1
       [child] => Array
       (
         [0] => Array
         (
           [id] => 4
           [label] => case
           [parent] => 3
           [child] => Array
           (
           )
        )

          [1] => Array
          (
            [id] => 5
            [label] => motherboard
            [parent] => 3
            [child] => Array
            (
            )
          )
       )
    )
  )
)

)

And i want to display in input select

computer->portable
computer->fixe->case
computer->fixe->motherboard

So I want to display all of the categories.

I think I can get there with a recursion.

Do you have any ideas?

The solution:

function listeParent($id){
$parent = ezine_query('SELECT * FROM itvgc_familles_articles WHERE famille_id="'.$id.'";');
$info_parent =mysqli_fetch_object($parent);

if ($info_parent->famille_parent!='') {
    listeParent($info_parent->famille_parent);
}

  echo $result .= $info_parent->famille_libelle.'>';
}

i loop on the array and i search the label

Chrill
  • 1
  • 2
  • Yes, this is quite easy with recursion - but you need to show at least some effort – kero Feb 20 '14 at 14:17
  • Maybe this will help you http://stackoverflow.com/questions/13399117/i-want-to-build-a-tree-with-this-array-these-are-the-ids-os-categories-and-su/13399290#13399290 – Kiro Coneski Feb 20 '14 at 14:34

0 Answers0