Table structure:
comment_id comment ID
arc_id article ID
content content
parent_id comment parent node
Want to get such a data structure recursively:
$arr=array(
[0]=>array(
comment_id=>1
parent_id =>0
['child']=>array(
[0]=>array(
comment_id=>2
parent_id =>1
)
[1]=>array(
comment_id=>3
parent_id =>2
)
[2]=>array(
comment_id=>4
parent_id =>1
)
........
)
)
[1]=>array(
comment_id=>5
parent_id =>0
['child']=>array(
[0]=>array(
comment_id=>6
parent_id =>5
)
[1]=>array(
comment_id=>7
parent_id =>5
)
[2]=>array(
comment_id=>8
parent_id =>7
)
........
)
)
)
First take out a two-dimensional array, each item has
comment_id
andparent_id
fieldsThen use the following function to convert the above two-dimensional array into a tree structure: