How can I add my Bootstrap classes to a custom menu? How can I add different Bootstrap menus to menu_tree_output()?

I know this is a very common question asked by a number of people earlier. I have found tons of answers, but none of them are working for me. However, I have tried a number snippets and here is the latest piece of code I am working on to get all menus and sub-menus.

&lt;?php 
  $menuTree = menu_tree_all_data('main-menu');
  $menu_tree_array = menu_tree_output($menuTree);
  print render($menu_tree_array);
?&gt;


It works and prints all the submenus, however, It adds the same "menu" class to all parent ul. Rather I would like add sub-menu classes like the below output:

&lt;div class="navbar-collapse collapse"&gt;
  &lt;div class="menu-top-menu-container"&gt;
    &lt;ul id="menu-top-menu" class="nav navbar-nav"&gt;
      &lt;li&gt;
        &lt;a href="http://example.com/"&gt;Home&lt;/a&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;a href="http://example.com/biography/"&gt;Biography&lt;/a&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;a href="#"&gt;Services&lt;/a&gt;
        &lt;ul class="sub-menu"&gt; &lt;!-- Like this. --&gt;
          &lt;li&gt;&lt;/li&gt;
          &lt;li&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;
&lt;/div&gt;
What you want is theme_menu_link(). See the example here.