Store categories in array by level in controller
You might just have to do it yourself :)

$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Category);
$criteria-&gt;group = 'groupHandle';
$categories = $criteria-&gt;find();
$sortedCategories = [];

foreach ($categories as $category) {
  if (!isset($sortedCategories[$category-&gt;level]) {
    $sortedCategories[$category-&gt;level] = [];
  }
  $sortedCategories[$category-&gt;level][] = $category;
}
var_dump($sortedCategories);


NOTE: I haven't tested this code, but in theory it should do the trick :)