I have a multidimensional messy tree array that I want to do as follows:
Extract each array, no matter how far it is nested, to fit it into a single “holder array”, so that’s (just a basic example, since it would be much more complicated than it would be when nested)
$this = array[0]=> (array[1]=>('a','b'),
array[2]=>(array[3]=>('c','d')));
will become something like this, it doesn’t matter if it changes the index for each array, just so that they are still in the array, but “flat”, so the only attachment is within the same main array of holders
$would_become = array[holder]=>(array[1]=>('a','b'),
array[2]=>(),
array[3]=>('c','d'));
The general argument for this is that I have a lot of nested arrays that have a common key, for example ['filepath'], and I want to be able to do something like below (I would have to go through each array in the holders array obviously, but this shows the basic idea why I need it.
foreach ($holder_array as $holder_array) {
echo $holder_array['Path']
}
source
share