I am trying to take a flat array and recreate it so that it\'s multidimensional. I\'ve been looking into array_combine and array_merge, but I\'m not sure that either of thos
Ok, I'm making some assumptions here:
parents
array will have only 1 tidGiven that, try this code:
$original = array ( ... your original array ... );
$nested = array ();
$n = count($original);
for ($i = 0; $i < $n; ++$i)
{
$nested[$original[$i]->tid] = $original[$i];
$nested[$original[$i]->tid]->children = array ();
}
while ($n-- && $current = $original[$n])
if ($current->parents[0] != 0 && $current->parents[0] != $current->tid)
{
$nested[$current->parents[0]]->children[] = $current;
unset ($nested[$current->tid]);
}