I'm trying to build a commenting system that renders nested comments. This function is working for me. However, I can't figure out where and how to "return" the data, as I don't want to echo this div.
The array I'm using is multidimensional where "child" contains nested comments.
function display_comments($commentsArr, $level = 0) {
foreach ($commentsArr as $info) {
$widthInPx = ($level + 1) * 30;
echo '<div style="width:' . $widthInPx . '"></div>';
if (!empty($info['childs'])) {
display_comments($info['childs'], $level + 1);
}
}
}