I’m having some issues with producing the right output with ($str .=) for some reason, but not with echo
[php] function displayComments($comments, $str){
foreach ($comments as $info) {
$str .= $info[‘id’];
if (!empty($info[‘childs’])) {
$this->displayComments($info[‘childs’],$str);
}
}
return $str;
}
$comments = $this->produceComments($id);
if(!$comments){
$str .=’
}else{
$str .= $this->displayComments($comments,’’);
}[/php]
$str .= $info[‘id’]; outputs 123
echo $info[‘id’]; outputs 125634 (which is the correct output)
array $comments is built fine.
Any idea why this would be outputting this way?
[code]Array
(
[1] => Array
(
[0] => 1
[id] => 1
[1] => 1
[project_id] => 1
[2] => 0
[parent] => 0
[3] => First post
[comment] => First post
[4] =>
[user] =>
[5] => 2014-02-01
[date] => 2014-02-01
[childs] => Array
(
)
)
[2] => Array
(
[0] => 2
[id] => 2
[1] => 1
[project_id] => 1
[2] => 0
[parent] => 0
[3] => Second Post
[comment] => Second Post
[4] =>
[user] =>
[5] => 2014-02-01
[date] => 2014-02-01
[childs] => Array
(
[0] => Array
(
[0] => 5
[id] => 5
[1] => 1
[project_id] => 1
[2] => 2
[parent] => 2
[3] => Reply to 2nd post
[comment] => Reply to 2nd post
[4] =>
[user] =>
[5] => 2014-02-05
[date] => 2014-02-05
[childs] => Array
(
)
)
[1] => Array
(
[0] => 6
[id] => 6
[1] => 1
[project_id] => 1
[2] => 2
[parent] => 2
[3] => Reply to 2nd post
[comment] => Reply to 2nd post
[4] =>
[user] =>
[5] => 2014-02-05
[date] => 2014-02-05
[childs] => Array
(
)
)
)
)
[3] => Array
(
[0] => 3
[id] => 3
[1] => 1
[project_id] => 1
[2] => 0
[parent] => 0
[3] => Reply to first post
[comment] => Reply to first post
[4] =>
[user] =>
[5] => 2014-02-19
[date] => 2014-02-19
[childs] => Array
(
[0] => Array
(
[0] => 4
[id] => 4
[1] => 1
[project_id] => 1
[2] => 3
[parent] => 3
[3] => Reply to first reply
[comment] => Reply to first reply
[4] =>
[user] =>
[5] => 2014-02-05
[date] => 2014-02-05
[childs] => Array
(
)
)
)
)
)[/code]