Можно вот так.
$select = [
"IBLOCK_ID",
"SECTION_ID" => "ID",
"SECTION_NAME" => "NAME",
"PARENT_ID" => "ROOT_SECTION.ID",
"PARENT_NAME" => "ROOT_SECTION.NAME",
];
$iblockId = 12;
$sections = [437, 494, 482];//массив из ID разделов для которых нужно получить корневые разделы
/** @var class-string<SectionTable> $entity */
$entity = \Bitrix\Iblock\Model\Section::compileEntityByIblock($iblockId);
$dbNavChain = $entity::getList([
"select" => $select,
"filter" => [
"=IBLOCK_ID" => $iblockId,
"ID" => $sections,
"=ROOT_SECTION.DEPTH_LEVEL" => 1
],
'runtime' => [
'ROOT_SECTION' => [
'data_type' => $entity,
'reference' => [
'=ref.IBLOCK_ID' => new \Bitrix\Main\DB\SqlExpression('?i', $iblockId),
'>this.LEFT_MARGIN' => 'ref.LEFT_MARGIN',
'<this.RIGHT_MARGIN' => 'ref.RIGHT_MARGIN',
]
]
],
"order" => [
"ROOT_SECTION.LEFT_MARGIN" => "ASC"
],
"cache" => [
"ttl" => 86400
]
]);
$result = [];
while ($navChain = $dbNavChain->fetch()) {
$section = [
"ID" => $navChain["PARENT_ID"],
"IBLOCK_ID" => $navChain["IBLOCK_ID"],
"NAME" => $navChain["PARENT_NAME"],
];
$result[$navChain["SECTION_ID"]] = $section;
}
print_r($result);
Результат:
Array
(
[437] => Array
(
[ID] => 75
[IBLOCK_ID] => 12
[NAME] => Гель-лаки
)
[482] => Array
(
[ID] => 338
[IBLOCK_ID] => 12
[NAME] => Инструменты
)
[494] => Array
(
[ID] => 338
[IBLOCK_ID] => 12
[NAME] => Инструменты
)
)