I have a php array (with comments) that needs to be ordered in different ways.
The order of the contents of the array should be like this:
parent
child
child
child
parent
child
child
etc.
Parent comments have "parent = 0". Child comments have an identifier for their parent (for example, "parent = 1"). Depth / number of comments for children is unknown.
How to get an array with the specified order when I have, for example, such an array?
Array
(
[0] => Array
(
[comment_id] => 1
[parent] => 0
)
[1] => Array
(
[comment_id] => 2
[parent] => 0
)
[2] => Array
(
[comment_id] => 3
[parent] => 1
)
[3] => Array
(
[comment_id] => 4
[parent] => 3
)
)
source
share