如何将树形数组,重新组合成一维数组
$arr=[
0 =>[
"id" =>"2",
"cate_name" =>"外用",
"parent_id" => "0",
"child" => [
0 => [
"id" => "5",
"cate_name" => "外1",
"parent_id" =>"2",
"child" =>[
0 => [
"id" =>"7",
"cate_name" => "外外1",
"parent_id" => "5",
"child" => NULL
]
]
],
1=>[
"id" => "6",
"cate_name" => "外2",
"parent_id" => "2",
"child" => NULL,
]
]
],
1 => [
"id" => "3",
"cate_name" =>"内用",
"parent_id" => "0",
"child" => NULL,
]
]
将这个三维数组分类树,组合成这种一维数组
$arr=[
0=>["id" =>"2","cate_name" =>"外用","parent_id" => "0",], //顶级分类
1=>["id" => "5","cate_name" => "外1","parent_id" =>"2",], //二级分类
2=>["id" =>"7","cate_name" => "外外1","parent_id" => "5",], //三级分类
3=>["id" => "6","cate_name" => "外2","parent_id" => "2",], //二级分类
4=>["id" => "3","cate_name" =>"内用","parent_id" => "0",],//顶级分类
];
求大神们帮忙。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个没难度啊
$i=0;
foreach ($arr as $key => $value) {
}
var_dump($array);
$result = [];
function getChild($parentId, $child)
{
}
getChild(0, $arr);
var_dump($result);