The first thing that comes to mind is just a flat version of what you have:
array ( [0] => array( 'name' => 'item1', 'parent' => null ), [1] => array( 'name' => 'item2', 'parent' => null ), [3] => array( 'name' => 'item3', 'parent' => 0 ), [4] => array( 'name' => 'item4', 'parent' => 3 ), [5] => array( 'name' => 'item5', 'parent' => 1 ), [6] => array( 'name' => 'item6', 'parent' => 1 ), );
Basically, you are only referring to the parent. To find all the children, you have to iterate over the array. However, the initial setup time would be pretty quick.
The second that comes to mind, and will include much more settings, but much less access time:
array ( [0] => array( 'name' => 'item1', 'parent' => null, 'children' = array(3) ), [1] => array( 'name' => 'item2', 'parent' => null 'children' = array(5, 6) ), [3] => array( 'name' => 'item3', 'parent' => 0 'children' = array(4) ), [4] => array( 'name' => 'item4', 'parent' => 3 'children' = array() ), [5] => array( 'name' => 'item5', 'parent' => 1 'children' = array() ), [6] => array( 'name' => 'item6', 'parent' => 1 'children' = array() ), );
In this, you add all the child indexes to the parent. This will take a little longer, but subsequent access times will be fast. When you figure out the parents, you simply add an array of parent children.
The only real drawback of the second approach is that if you want to add or remove an element, you need to remember to return and update the children array for the parent.