function gettree($arr)
{
    $tree = array();
    foreach ($arr as $val) {
        if (isset($arr[$val['pid']]))// 如果等于0 表示顶级目录  但凡是pid=0 $arr[0] 不存在  走else
        {
            $arr[$val['pid']]['son'][] = &$arr[$val['id']]; //非顶级分类
        } else {
            $tree[] =& $arr[$val['id']];
        }
    }
    return $tree;
}
$arr = array(
    1 => array('id' => 1, 'pid' => 0, 'name' => '河南省'),
    2 => array('id' => 2, 'pid' => 0, 'name' => '河北省'),
    3 => array('id' => 3, 'pid' => 1, 'name' => '郑州市'),
    4 => array('id' => 4, 'pid' => 3, 'name' => '高新区'),
    5 => array('id' => 5, 'pid' => 1, 'name' => '洛阳市'),
    6 => array('id' => 6, 'pid' => 0, 'name' => '山东'),

);
Array
(
    [0] => Array
        (
            [id] => 1
            [pid] => 0
            [name] => 河南省
            [son] => Array
                (
                    [0] => Array
                        (
                            [id] => 3
                            [pid] => 1
                            [name] => 郑州市
                            [son] => Array
                                (
                                    [0] => Array
                                        (
                                            [id] => 4
                                            [pid] => 3
                                            [name] => 高新区
                                        )

                                )

                        )

                    [1] => Array
                        (
                            [id] => 5
                            [pid] => 1
                            [name] => 洛阳市
                        )

                )

        )

    [1] => Array
        (
            [id] => 2
            [pid] => 0
            [name] => 河北省
        )

    [2] => Array
        (
            [id] => 6
            [pid] => 0
            [name] => 山东
        )

)

上面生成树方法还可以精简到5行:

PHP
function generateTree($arr){
    foreach($arr as $val)
        $arr[$val['pid']]['son'][$val['id']] = &$arr[$val['id']];
    return isset($arr[0]['son']) ? $arr[0]['son'] : array();
}