I need to transform an array of parents to children into an array of children to parents. For example, I have an array like this:
[
1 => [a,b,c],
2 => [b,c,d],
3 => [c,d,e],
]
And I want to turn it into this:
[
a => [1],
b => [1,2],
c => [1,2,3],
d => [2,3],
e => [3]
]
Is there a way to accomplish this task without using nested foreach loops? If not, what is the most efficient way to do so?
Thanks in advance!