WordPress Version: 5.8
/**
* Outputs nested array of pages
*
* @param array $current_level The level being iterated through.
* @param array $children The children grouped by parent post ID.
*
* @return array The nested array of pages.
*/
function block_core_page_list_nest_pages($current_level, $children)
{
if (empty($current_level)) {
return;
}
foreach ((array) $current_level as $key => $current) {
if (isset($children[$key])) {
$current_level[$key]['children'] = block_core_page_list_nest_pages($children[$key], $children);
}
}
return $current_level;
}