phprs\util\Tree::erase PHP Method

erase() public method

删除一个路径下的所有节点
public erase ( array $path ) : boolean
$path array
return boolean
    public function erase(array $path)
    {
        if (count($path) == 0) {
            return false;
        }
        $size = count($path);
        $key = $path[$size - 1];
        if ($size == 1) {
            if (array_key_exists($key, $this->arr)) {
                unset($this->arr[$key]);
                return true;
            }
            return false;
        }
        $i = 0;
        $res = false;
        $full = $this->visitNode($path, function ($name, &$node) use(&$i, $size, $key, &$res) {
            if (++$i == $size - 1) {
                if (isset($node['next']) && isset($node['next'][$key])) {
                    unset($node['next'][$key]);
                    $res = true;
                }
                return false;
            }
            return true;
        }, true);
        return $res;
    }