Array(
[3] => other
[13] => MAZ
[11] => LOL
[9] => pack
)
Array(
[13] => 11
[11] => 9
)
Array(11, 13)
$dirMapping = [
3 => 'other'
13 => 'MAZ'
11 => 'LOL'
9 => 'pack'
];
$hierarchy = [
13 => 11
11 => 9
];
$ids = [11, 13];
$paths = [];
foreach ($ids as $current) {
$path = [];
// повторяем пока мы не дойдем до последнего
while(isset($hierarchy[$current])){
$path[] = $dirMapping[$current];
$current = $hierarchy[$current];
};
$path[] = $dirMapping[$current];
$paths[] = join(':', array_reverse($path));
}