original_string: private function add_to_parent_category_branch($category, $newnode, &$categoriesbranch) {
  
          foreach ($categoriesbranch as $key => $branch) {
              if (!empty($branch['categoryid']) && $branch['categoryid'] == $category->parent) {
                  // It may be empty (if it does not contain courses and this is the first child cat).
                  if (!isset($categoriesbranch[$key]['branches'])) {
                      $categoriesbranch[$key]['branches'] = [];
                  }
                  $categoriesbranch[$key]['branches'][] = $newnode;
                  return true;
              }
              if (!empty($branch['branches'])) {
                  $parent = $this->add_to_parent_category_branch($category, $newnode, $categoriesbranch[$key]['branches']);
                  if ($parent) {
                      return true;
                  }
              }
          }
  
          return false;
      }
code: private function add_to_parent_category_branch($category, $newnode, &$categoriesbranch) {
  
          foreach ($categoriesbranch as $key => $branch) {
              if (!empty($branch['categoryid']) && $branch['categoryid'] == $category->parent) {
                  // It may be empty (if it does not contain courses and this is the first child cat).
                  if (!isset($categoriesbranch[$key]['branches'])) {
                      $categoriesbranch[$key]['branches'] = [];
                  }
                  $categoriesbranch[$key]['branches'][] = $newnode;
                  return true;
              }
              if (!empty($branch['branches'])) {
                  $parent = $this->add_to_parent_category_branch($category, $newnode, $categoriesbranch[$key]['branches']);
                  if ($parent) {
                      return true;
                  }
              }
          }
  
          return false;
      }
code_tokens: private function add_to_parent_category_branch ( $ category , $ newnode , & $ categoriesbranch ) { foreach ( $ categoriesbranch as $ key => $ branch ) { if ( ! empty ( $ branch [ 'categoryid' ] ) && $ branch [ 'categoryid' ] == $ category -> parent ) { // It may be empty (if it does not contain courses and this is the first child cat). if ( ! isset ( $ categoriesbranch [ $ key ] [ 'branches' ] ) ) { $ categoriesbranch [ $ key ] [ 'branches' ] = [ ] ; } $ categoriesbranch [ $ key ] [ 'branches' ] [ ] = $ newnode ; return true ; } if ( ! empty ( $ branch [ 'branches' ] ) ) { $ parent = $ this -> add_to_parent_category_branch ( $ category , $ newnode , $ categoriesbranch [ $ key ] [ 'branches' ] ) ; if ( $ parent ) { return true ; } } } return false ; }
docstring: Adds the provided category to the categories branch.
  
  @param stdClass $category
  @param array $newnode
  @param array $categoriesbranch
  @return bool
docstring_tokens: Adds the provided category to the categories branch .