One question is if you really want to get rid of your objects. And if you do, why you don't want to get rid of the one residing in Array[0].
Also, I would have expected the name Object->parent, containing the id of the parent, Object->parents is an array. What is the purpose of this? Is this real life ancestry, so that each child has two parents? Or is parents an array containing a complete ancestry in a tree where each child has only one parent?
Anyway, assuming there is only one parent, the easiest way of achieving a multidimensional array is probably like this
# get rid of your objects and use tid as array key.
$flat = array();
foreach($orig as $o) {
$flat[$o->tid]['tid'] = $o->tid;
$flat[$o->tid]['name'] = $o->name;
$flat[$o->tid]['parent'] = $o->parent;
}
# $new will only contain top level elements.
# $flat will no longer be flat.
$new = array();
foreach($flat as $k => $v) {
if ($v['parent'] == 0) {
$new[$v['tid']] = &$flat[$k];
}
else
$flat[$v['parent']]['children'][] = &$flat[$k];
This should be modifiable to match the actual functionality of your parents array.