得到孩子的父母子女

I manage to get parent and child but I'm having trouble getting children of child

THis is how the pages looks like.

  [0] => array(1) {
    ["PARENT"] => string(0) ""
  }
  [1] => array(2) {
    ["PARENT"] => string(10) " Hang TED"
    ["CHILD"] => array(2) {
      [0] => array(1) {
        ["CHILD"] => string(13) "110379 110626"
      }
      [1] => array(1) {
        ["CHILD"] => string(13) "110417 110626"
      }
    }
  }
<?php

$pages = array('0'=>array(
                'parent'=> 'parent0',
                'child' => array('name' => 'test', 'children' => array(
                        array('child' => 'child1'),
                        array('child' => 'child2')                    
                    ))
               ),
               '1' => array('parent'=>'parent1')
               );


$arr_pages = getDetails($pages);

function getDetails(array $pages) {
    $result = array();
    if(count($pages)) {
        foreach($pages as $key => $value) {
             $cnames=array();
            if($value['parent']) $result[$key]['parentname'] = $value['parent'];
            if($value['child']['name']) $result[$key]['childname'] =  $value['child']['name'];
            if(is_array($value['child']['children'])) {
                   foreach($value['child']['children'] as $cval) $cnames[] = $cval['child'];
                    $result[$key]['childrenofchild'] = implode(',',$cnames);
            }

        }
    }
    return $result;
}

I did it in a very basic way considering there the depth of array will be no more than 3 levels. And you will be expecting the o/p as

Array
(
    [0] => Array
        (
            [parentname] => parent0
            [childname] => test
            [childrenofchild] => child1,child2
        )

    [1] => Array
        (
            [parentname] => parent1
        )

)