将数组关联到嵌套集


associative array to nested set

我正在尝试获取关联数组的嵌套集合数据。数组需要作为嵌套集存储在 mysql 数据库中。我想获取嵌套集数据的数组:嵌套集实现的链接http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/

Array
(
    [NEOPLASMS OF MATURE T CELLS OR NK CELLS] => Array
        (
            [Adult T-cell leukemia/lymphoma] => Array
                (
                    [1] => Helper T cell
                    [2] => HTLV-1 provirus present in tumor cells
                    [3] => Adults with cutaneous lesions, marrow involvement, and hypercalcemia; occurs mainly in Japan, West Africa, and the Caribbean; aggressive
                )
            [Peripheral T-cell lymphoma, unspecified] => Array
                (
                    [4] => Helper or cytotoxic T cell
                    [5] => No specific chromosomal abnormality
                    [6] => Mainly older adults; usually presents with lymphadenopathy; aggressive
                )
            [Anaplastic large-cell lymphoma] => Array
                (
                    [7] => Cytotoxic T cell
                    [8] => Rearrangements of ALK
                    [9] => Children and young adults, usually with lymph node and soft-tissue disease; aggressive
                )
            [Extranodal NK/T-cell lymphoma] => Array
                (
                    [10] => NK-cell (common) or cytotoxic T cell (rare)
                    [11] => EBV-associated; no specific chromosomal abnormality
                    [12] => Adults with destructive extranodal masses, most commonly sinonasal; aggressive
                )
            [Mycosis fungoides/Sézary syndrome] => Array
                (
                    [13] => Helper T cell
                    [14] => No specific chromosomal abnormality
                    [15] => Adult patients with cutaneous patches, plaques, nodules, or generalized erythema; indolent
                )
            [Large granular lymphocytic leukemia] => Array
                (
                    [16] => Two types: cytotoxic T cell and NK cell
                    [17] => No specific chromosomal abnormality
                    [18] => Adult patients with splenomegaly, neutropenia, and anemia, sometimes, accompanied by autoimmune disease
                )
        )
)

我想要的数组输出:

Array
(
    [0] => Array
        (
            [0] => NEOPLASMS OF MATURE T CELLS OR NK CELLS
            [1] => 1
            [2] => 26
        )
    [1] => Array
        (
            [0] => Adult T-cell leukemia/lymphoma
            [1] => 2
            [2] => 9
        )
.

.....等等。

这是我被困的地方:

    class nested_data
{
    var $nc = 1;
    var $map;
    var $nest = array();
    function make_nest()
    {
        array_walk($this->map, array($this,"fetch_nest_data"));
        foreach($this->map as $map)
        {
            array_walk($map,array($this,"fetch_nest_data"));
        }
    }

    function fetch_nest_data($val,$key)
    {
        $content = (is_array($val)) ? $key : $val;
        $lft = $this->nc++;
        $rgt= (is_array($val)) ? (count($val, COUNT_RECURSIVE) + $this->nc) : $this->nc++;
        $this->nest[]=array($content,$lft,$rgt);
    }

}

感谢您的帮助!

我所做的是创建一个嵌套的集合管理器,其中包含诸如addChild(),addSibling(),moveNodeUp(),moveNodedown(),setNodePosition()等方法或函数。 从那里你可以循环访问数组、文本文件表示形式等,并很快将它们转换为嵌套集。最困难的部分是分解所有小节点运动。