일반 배열을 카테고리 및 하위 카테고리 형태로 구현한 소스입니다.

 <?php
 $list = array(
        array(
'idx' => 1,  'parent_id' => 0),
        array(
'idx' => 2,  'parent_id' => 0),
        array(
'idx' => 3,  'parent_id' => 0),
        array(
'idx' => 4,  'parent_id' => 0),
        array(
'idx' => 5,  'parent_id' => 0),
        array(
'idx' => 6,  'parent_id' => 2),
        array(
'idx' => 7,  'parent_id' => 2),
        array(
'idx' => 8,  'parent_id' => 3),
        array(
'idx' => 9,  'parent_id' => 4),
        array(
'idx' => 10'parent_id' => 9)
 );
$tree Tree_Array($list'idx''parent_id');
print_r($tree);

function 
Tree_Array($atr$id='id'$parent_id='parent'$children='children')
{
    
$nlist = array(
        array( 
$children => array() )
    );
    
$raw = array(&$nlist[0]);
    if(isset(
$atr))
    {
        foreach(
$atr as $q => $w)
        {
            
$raw[$w[$parent_id]][$children][$w[$id]] = $w;
            
$raw[$w[$id]] = &$raw[$w[$parent_id]][$children][$w[$id]];
        }
    }
    return 
$nlist[0][$children];
}
/*
결과:
Array
(
    [1] => Array
        (
            [idx] => 1
            [parent_id] => 0
        )
    [2] => Array
        (
            [idx] => 2
            [parent_id] => 0
            [children] => Array
                (
                    [6] => Array
                        (
                            [idx] => 6
                            [parent_id] => 2
                        )
                    [7] => Array
                        (
                            [idx] => 7
                            [parent_id] => 2
                        )
                )
        )
    [3] => Array
        (
            [idx] => 3
            [parent_id] => 0
            [children] => Array
                (
                    [8] => Array
                        (
                            [idx] => 8
                            [parent_id] => 3
                        )
                )
        )
    [4] => Array
        (
            [idx] => 4
            [parent_id] => 0
            [children] => Array
                (
                    [9] => Array
                        (
                            [idx] => 9
                            [parent_id] => 4
                            [children] => Array
                                (
                                    [10] => Array
                                        (
                                            [idx] => 10
                                            [parent_id] => 9
                                        )
                                )
                        )
                )
        )
    [5] => Array
        (
            [idx] => 5
            [parent_id] => 0
        )
)
*/
?>