0

我有正确的以下代码来设置父子数组结构,如..

$refs = array();
$list = array();

            while($QryRow_Category_sub = mysqli_fetch_assoc($QryResult_Category)) 
            {
                $thisref = &$refs[$QryRow_Category_sub['id']];

                $thisref['parent_id'] = $QryRow_Category_sub['parent_id'];
                $thisref['name'] = $QryRow_Category_sub['name'];

                if ($QryRow_Category_sub['parent_id'] == 0) {
                //echo &$thisref;
                    $list[$QryRow_Category_sub['id']] = &$thisref;
                } else {
                    $refs[$QryRow_Category_sub['parent_id']]['children'][$QryRow_Category_sub['id']] = &$thisref;
                }
            }

这是我的输出

   Television Cat - 1
      Television Cat - 1 Sub Cat - 1
      Television Cat - 1 Sub Cat - 2
   Television Cat - 2
      Television Cat - 2 Sub Cat - 1
   Television Cat - 3
      Television Cat - 3 Sub Cat - 1
   Television Cat - 4
      Television Cat - 4 Sub Cat - 1

   Television Cat - 1 Sub Cat - 1
   Television Cat - 1 Sub Cat - 2
   Television Cat - 2 Sub Cat - 1
   Television Cat - 3 Sub Cat - 1
   Television Cat - 4 Sub Cat - 1

这是我的代码,我得到了很好的结果,但我有一个问题。但我想从输出中删除以下代码

Television Cat - 1 Sub Cat - 1
   Television Cat - 1 Sub Cat - 2
   Television Cat - 2 Sub Cat - 1
   Television Cat - 3 Sub Cat - 1
   Television Cat - 4 Sub Cat - 1

这是子类别的重复条目。

请给出解决方案。谢谢你。

4

0 回答 0