在php数组中显示整个树

时间:2014-02-20 14:12:50

标签: php arrays

我有一个看起来像这样的数组

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
            (
            )
          )
       )
    )
  )
)

我想在输入选择中显示

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

所以我想显示所有类别。

我想我可以通过递归到达那里。

你有什么想法吗?

解决方案:

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.'>';
}

我在数组上循环,我搜索标签

0 个答案:

没有答案