private function getTaxonomyChildren(array $parent, $hyphens = 0) {
    $children = [];
    $selected = [];

    foreach ($parent['children'] as $tid => $child) {
      $children[$tid] = str_repeat('-', $hyphens) . $child['label'];
      if ($child['selected']) {
        $selected[] = $tid;
      }
      if (!empty($child['children'])) {
        $result = $this->getTaxonomyChildren($child, $hyphens + 1);
        $children += $result['children'];
        $selected += $result['selected'];
      }
    }

    return [
      'children' => $children,
      'selected' => $selected,
    ];
  }
private function getTaxonomyChildren(array $parent, $hyphens = 0) {
    $children = [];
    $selected = [];

    foreach ($parent['children'] as $tid => $child) {
      $children[$tid] = str_repeat('-', $hyphens) . $child['label'];
      if ($child['selected']) {
        $selected[] = $tid;
      }
      if (!empty($child['children'])) {
        $result = $this->getTaxonomyChildren($child, $hyphens + 1);
        $children += $result['children'];
        $selected += $result['selected'];
      }
    }

    return [
      'children' => $children,
      'selected' => $selected,
    ];
  }
private function getTaxonomyChildren ( array $ parent , $ hyphens = 0 ) { $ children = [ ] ; $ selected = [ ] ; foreach ( $ parent [ 'children' ] as $ tid => $ child ) { $ children [ $ tid ] = str_repeat ( '-' , $ hyphens ) . $ child [ 'label' ] ; if ( $ child [ 'selected' ] ) { $ selected [ ] = $ tid ; } if ( ! empty ( $ child [ 'children' ] ) ) { $ result = $ this -> getTaxonomyChildren ( $ child , $ hyphens + 1 ) ; $ children += $ result [ 'children' ] ; $ selected += $ result [ 'selected' ] ; } } return [ 'children' => $ children , 'selected' => $ selected , ] ; }
Reaches into all children and flattens the taxonomy.

This method is private for a reason. We don't handle extra nesting yet but
could want to do this in the future. Do not rely on this method existing
in the future.

@param array $parent
The parent whose children to recurse through.
@param int $hyphens
The number of hyphens to use as a label prefix.

@return array[]
A flattened array of children.
Reaches into all children and flattens the taxonomy .