Answer the question
In order to leave comments, you need to log in
How to write code for this task?
There are arrays:
Key - folder id, value - folder name :
Array(
[3] => other
[13] => MAZ
[11] => LOL
[9] => pack
)
Array(
[13] => 11
[11] => 9
)
Array(11, 13)
Answer the question
In order to leave comments, you need to log in
$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));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question