I'm trying to use a recursive function to build an array with inheritance.
Let's say I have an object "a" that looks like this (with a Parent ID of "b")
a = 'Item 1', 'Item 2', Parent_ID, 'Item 3', 'Item 4'
And I have an object "b" that looks like this:
b = 'Item X', 'Item Y'
And the desired result is this:
final = 'Item 1', 'Item 2', 'Item X', 'Item Y', 'Item 3', 'Item 4'
So basically array_splice function that continues to look for a parent ID and inserts the parent items. I'm going this direction on the code:
$master_list = array();
getItems("a", $master_list);
function getItems($ID, &$master_list){
$master_list = retrieve_items($ID); // returns items from "a"
//if Parent ID exists, run function again to retrieve items from parent and insert them in place of the Parent ID
if(Parent_ID)
array_splice($master_list, [parent index], 1, getItems($parentID, $master_list);
}
My function is returning this as the (undesired) result:
final = 'Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item X', 'Item Y'
Obviously this is pseudo-code and is only intended to get the point across. Can anyone point me in the right direction? I greatly appreciate it.