I'm trying to insert data into a multidimensional array but it get's me struggled. I'm unable to do it. It's so confusing for me.
I have a "tree" array:
$tree = array(
10 => array(),
11 => array(
4 => array(),
5 => array(),
6 => array()
)
);
And the array of the path I have to use to insert the data:
$path = array(11,5);
The result should be:
$tree = array(
10 => array(),
11 => array(
4 => array(),
5 => array($data),
6 => array()
)
);
This must work with any multidmensional array (n-dimensional).
As a note, the insertion will always take place in one of the deepest branches of the tree. For example, if the tree is a three-dimensional array, the path variable will have 3 values for sure and the insertion will be in one of the n three-dimensional branches the array could have.
I would type here what I have done but is not so much. I event don't know if I should choose a recursive function to do it or other way.
Thanks in advance.
4 => array( 1=>array(), 2=>array() ),$path?