Array
(
[0] => Array
(
[category_id] => 1
[parent_id] =>
[alias] => /platya
[name] => Платья
[translit] =>
)
[1] => Array
(
[category_id] => 2
[parent_id] => 1
[alias] => /platya/tuniki
[name] => Туники
[translit] =>
)
[2] => Array
(
[category_id] => 3
[parent_id] => 1
[alias] => /platya/sarafany
[name] => Сарафаны
[translit] =>
)
[3] => Array
(
[category_id] => 4
[parent_id] => 1
[alias] => /platya/mini
[name] => Мини
[translit] =>
)
[4] => Array
(
[category_id] => 5
[parent_id] => 1
[alias] => /platya/midi
[name] => Миди
[translit] =>
)
[5] => Array
(
[category_id] => 6
[parent_id] => 1
[alias] => /platya/maksi
[name] => Макси
[translit] =>
)
[6] => Array
(
[category_id] => 7
[parent_id] => 2
[alias] => /platya/maksi/super
[name] => Супер
[translit] =>
)
)
$data = [];
foreach($array as $item) {
if ($item['category_id'] == $item['parent_id']) $data[] = $item;
}
function createTree($data, $idField, $parentField, $rootParent) {
foreach ($data as $n) {
$tree[$n[$idField]] = $n;
}
foreach ($data as $n) {
$tree[$n[$parentField]]['children'][] = &$tree[$n[$idField]];
}
return $tree[$rootParent]['children'];
}
$tree = createTree($arr, 'category_id', 'parent_id', '');