说明:parent array中含有唯一pid,pid通过调用M层获取子数组内容,要求parent数组和child数组拥有相同的key,然后合并成一起
code:
foreach($parentArray as $v){
    $a['id']=$v['pid'];
    $a['name'] =$v['name'];
    ...
    $array[] =$a;
    $childContent = $m->getChildContent($v['pid']);
    foreach($childContent as $v2){
        $b['id']=$v2['cid'];
        $b['name']=$v2['cname'];
        ...
        $array2[]=$b;
    }
}
我想让输出这样的格式
array[0]{
    $array里的内容,
    $array2里的内容
}
array[1]{
   $array,
   $array2,
}
因为是无限分级,想将foreach遍历数组中第一个和child数组 组合成一起,做为一个数组,
最后输出样式:
parent父栏目
   --child子栏目
parent父栏目
   --child子栏目
parent父栏目
   --child子栏目
.....
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
不知道你说的是不是跟无限分类类似的情况。
如果parent和child是放在同一个表(应该也是)
如果只有两层的话,我通常是这么做的
那么查询时按照pid排序
然后遍历数组
如果是需要三层例如
这样的话,我觉得这种方式的有点自找麻烦了。
参考资料:
http://www.cnblogs.com/yangmanyan/archive/2011/06/16/2082963.html抱歉更新一下,从数据库查询出来的结果,哪怕字段类型是整型,查询出来也是字符串。
所以应该是
$v['pid'] == 0或者$v['pid'] === '0'。要转化成:O:27:"GuzzleHttp\Cookie\CookieJar":2: