Php 解析多维数组类别树

Php 解析多维数组类别树,php,Php,我有一个这样的分类树: 我想用以下列将其解析到我的表中:category\u name、category\u id和parent\u id stdClass Object ( [Name] => Shoes [CategoryId] => 661 [GlobalIdentifier] => [Children] => stdClass Object ( [Category] => Array ( [0] => stdCla

我有一个这样的分类树: 我想用以下列将其解析到我的表中:category\u name、category\u id和parent\u id

stdClass Object
(
 [Name] => Shoes
 [CategoryId] => 661
 [GlobalIdentifier] => 
 [Children] => stdClass Object
  (
   [Category] => Array
    (
     [0] => stdClass Object
      (
       [Name] => Female Shoes
       [CategoryId] => 3
       [GlobalIdentifier] => 
       [Children] => stdClass Object
        (
         [Category] => Array
          (
           [0] => stdClass Object
            (
             [Name] => Shoes type 1
             [CategoryId] => 2082
             [GlobalIdentifier] => 
             [Children] => 
            )

           [1] => stdClass Object
            (
             [Name] => Shoes type 2
             [CategoryId] => 50
             [GlobalIdentifier] => 
             [Children] => 
            )

           [2] => stdClass Object
            (
             [Name] => Shoes type 3
             [CategoryId] => 2098
             [GlobalIdentifier] => 
             [Children] => 
            )

           [3] => stdClass Object
            (
             [Name] => Shoes type 4
             [CategoryId] => 7
             [GlobalIdentifier] => 
             [Children] => stdClass Object
              (
               [Category] => Array
                (
                 [0] => stdClass Object
                  (
                   [Name] => Shoes type 5
                   [CategoryId] => 2797
                   [GlobalIdentifier] => 
                   [Children] => 
                  )
我正在尝试构建一个函数来解析这棵树。这就是我现在拥有的,但它仍然不起作用。因为我可以一直到树的最后一个节点,但不能返回到它的父节点继续。我怎样才能解决这个问题

$categoriesArr = $categories->Categories->Category[0];

function parseCategories($root, $parentId, $parentNode, $returnArr, $arrayNode = array(), $arrayIndex = -1){

 var_dump('debug: '. var_export($returnArr, true));
 if (is_array($root) == false && is_object($root)){
  if (isset($root->Name)){
   $returnArr[] = array('category_id' => $root->CategoryId, 'name' => $root->Name, 'parent_id' => $parentId);

   print_r($root);
   print_r("parentid ".$parentId);

   if (isset($root->Children) && !empty($root->Children)) {
    if (isset($root->Children->Category)) {

     return parseCategories($root->Children->Category, $root->CategoryId, $root, $returnArr);

    }
    else {

     if (count($arrayNode) > $arrayIndex+1){
      print_r("count ".count($arrayNode));
      print_r("arrayIndex ".$arrayIndex+1);
      return parseCategories($arrayNode, $parentId, $parentNode, $returnArr, $arrayNode, $arrayIndex);
     }
     else {
      print_r("abc");

     }

    }
   }
   else {

    return $returnArr;
   }

  }
 }