How to turn a menu tree into an associative array?
You can load up the menu tree with MenuLinkTree::load, which will give you an array of menu links to work with. From there it's just a matter of looping through and getting what you need, e.g.

$tree = \Drupal::menuTree()-&gt;load('main', new \Drupal\Core\Menu\MenuTreeParameters());
foreach ($tree as $item) {
  $title = $item-&gt;link-&gt;getTitle();
  $url_obj = $item-&gt;link-&gt;getUrlObject();
  $has_children = $item-&gt;hasChildren;
  // etc...
}


The link is a MenuLinkInterface, each item itself is a MenuLinkTreeElement.

It would be preferable to inject the menu.link_tree service if possible, rather than getting it from \Drupal.