Automattic\WooCommerce\Internal\Admin
CategoryLookup::unflatten_terms()
Convert flat terms array into nested array.
Метод класса: CategoryLookup{}
Хуков нет.
Возвращает
null
. Ничего (null).
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->unflatten_terms( $hierarchy, $terms, $parent );
- $hierarchy(массив) (обязательный) (передается по ссылке — &)
- Array to put terms into.
- $terms(массив) (обязательный) (передается по ссылке — &)
- Array of terms (id=>parent).
- $parent(int)
- Parent ID.
Код CategoryLookup::unflatten_terms() CategoryLookup::unflatten terms WC 8.7.0
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 ); } }