Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 关联数组到嵌套集_Php_Nested Sets - Fatal编程技术网

Php 关联数组到嵌套集

Php 关联数组到嵌套集,php,nested-sets,Php,Nested Sets,我正在尝试获取关联数组的嵌套集数据。数组需要作为嵌套集存储在mysql数据库中。要获取嵌套集数据的数组: 用于嵌套集实现的链接 我想要的数组输出: Array ( [0] => Array ( [0] => NEOPLASMS OF MATURE T CELLS OR NK CELLS [1] => 1 [2] => 26 ) [1] => A

我正在尝试获取关联数组的嵌套集数据。数组需要作为嵌套集存储在mysql数据库中。要获取嵌套集数据的数组: 用于嵌套集实现的链接

我想要的数组输出:

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等方法或函数。从那里,您可以循环遍历数组、文本文件表示形式,然后快速地将它们转换为嵌套集。最难的部分是分解所有的小节点运动。

对不起,你所描述的对我来说毫无意义。第一个数组中的1和26来自何处?实际上应该是1和47,手动进行计算。但我想通过编程来实现这一点。
    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);
    }



}