Fairly hard one to explain, but effectively I've got an array of items which have IDs, of which can contain a list of IDs for other array items. for example
$items = [
[id: 'one', deps: ['three']],
[id: 'two'],
[id: 'three', deps: ['four', 'two']],
[id: 'four']
];
So as you can see here, one depends on three, and three depends on four and two.
I need to get a new array, that contains these items in order - so that the dependencies are listed in order. So the above array would convert into
$items = [
[id: 'four'],
[id: 'two'],
[id: 'three', deps: ['four', 'two']],
[id: 'one', deps: ['three']]
];
How would I complete this? I've tried various while loops checking for item positions, but can't crack it.
Thanks
UPDATE Some people have said its a duplicate question of THIS but the main difference being the above example has multiple dependencies - whereas the mentioned thread only works on a single string dependency