请问一个简单的递归
程序员文章站
2022-05-10 10:00:08
...
请教一个简单的递归
$arr = array(
array(
'id' => 1,
'parentid' => 0,
'title' => 'a'
),
array(
'id' => 2,
'parentid' => 1,
'title' => 'a-1'
),
array(
'id' => 3,
'parentid' => 1,
'title' => 'a-1'
),
array(
'id' => 4,
'parentid' => 2,
'title' => 'a-1-1'
)
);
递归转换为数组如下:
$arr = array(
array(
'id' => 1,
'parentid' => 0,
'title' => 'a',
'child' => array(
array(
'id' => 2,
'parentid' => 1,
'title' => 'a-1',
'child' => array(
......
)
array(
'id' => 3,
'parentid' => 2,
'title' => 'a-2'
)
),
......
);
请问要如何写这个递归呢?
$arr = array(
array(
'id' => 1,
'parentid' => 0,
'title' => 'a'
),
array(
'id' => 2,
'parentid' => 1,
'title' => 'a-1'
),
array(
'id' => 3,
'parentid' => 1,
'title' => 'a-1'
),
array(
'id' => 4,
'parentid' => 2,
'title' => 'a-1-1'
)
);
递归转换为数组如下:
$arr = array(
array(
'id' => 1,
'parentid' => 0,
'title' => 'a',
'child' => array(
array(
'id' => 2,
'parentid' => 1,
'title' => 'a-1',
'child' => array(
......
)
array(
'id' => 3,
'parentid' => 2,
'title' => 'a-2'
)
),
......
);
请问要如何写这个递归呢?
相关文章
相关视频
上一篇: php 问卷调查结果统计,php问卷调查统计_PHP教程
下一篇: 关于简单选择的详细介绍