WordPress at a glance
function is not described

Automattic\WooCommerce\Admin

CategoryLookup::unflatten_terms() protected WC 1.0

Convert flat terms array into nested array.

{} It's a method of the class: CategoryLookup{}

No Hooks.

Return

null. Nothing.

Usage

// protected - for code of main (parent) or child class
$result = $this->unflatten_terms( $hierarchy, $terms, $parent );
$hierarchy(array) (required)
Array to put terms into.
$terms(array) (required)
Array of terms (id=>parent).
$parent(int)
Parent ID.

Code of CategoryLookup::unflatten_terms() WC 5.3.0

<?php
protected function unflatten_terms( &$hierarchy, &$terms, $parent = 0 ) {
	foreach ( $terms as $term_id => $parent_id ) {
		if ( (int) $parent_id === $parent ) {
			$hierarchy[ $term_id ] = array(
				'term_id'     => $term_id,
				'descendants' => array(),
			);
			unset( $terms[ $term_id ] );
		}
	}
	foreach ( $hierarchy as $term_id => $terms_array ) {
		$this->unflatten_terms( $hierarchy[ $term_id ]['descendants'], $terms, $term_id );
	}
}