Following is my array output.
Array
(
[0] => Array
(
[id] => 1011
[user_id] => 168
[item_id] => 831
[post_content] => My New Post 20
[parent_comment_id] => 1010
[name] => a
[children] => Array
(
[0] => Array
(
[id] => 1012
[user_id] => 168
[item_id] => 831
[parent_comment_id] => 1011
[name] => a
[children] => Array
(
[0] => Array
(
[id] => 1013
[user_id] => 179
[item_id] => 831
[parent_comment_id] => 1012
[name] => a
[children] => Array
(
[0] => Array
(
[id] => 1014
[user_id] => 168
[item_id] => 831
[parent_comment_id] => 1013
[name] => a
)
)
)
)
)
)
)
)
I only want to remove following array keys only from children array.
item_id
parent_comment_id
name
I have tried to remove but it also remove from starting array also , I just want to remove that keys only from children array.
Following is my code...
$arr = array(
array('id'=>1011, 'user_id' => 168, 'item_id'=>831, 'post_content'=>'My New Post 20', 'parent_comment_id'=>1010, 'name'=>'a'),
array('id'=>1012,'user_id' => 168, 'item_id'=>831 ,'parent_comment_id'=>1011, 'name'=>'a'),
array('id'=>1013, 'user_id' => 179, 'item_id'=>831, 'parent_comment_id'=>1012, 'name'=>'a'),
array('id'=>1014,'user_id' => 168, 'item_id'=>831, 'parent_comment_id'=>1013, 'name'=>'a'),
);
echo "<pre> add";print_r($arr);
$new = array();
foreach ($arr as $a){
$new[$a['parent_comment_id']][] = $a;
}
$tree = createTree($new, array($arr[0]));
print_r($tree);
function createTree(&$list, $parent){
$tree = array();
foreach ($parent as $k=>$l){
if(isset($list[$l['id']])){
$l['children'] = createTree($list, $list[$l['id']]);
//unset($l['item_id']);
}
$tree[] = $l;
}
return $tree;
}