plook/tree 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

plook/tree

最新稳定版本:0.5.0

Composer 安装命令:

composer require plook/tree

包简介

Library for working with tree data structures.

README 文档

README

codecov

A PHP library for working with tree data structures.

Installation

$ composer require plook/tree

Working with trees that are stored in arrays

Traversing a left/right tree that is ordered by the left value

$tree = [
    ['id' => 1, 'left' => 1, 'right' => 14],
    ['id' => 2, 'left' => 2, 'right' => 7],
    ['id' => 3, 'left' => 3, 'right' => 4],
    ['id' => 4, 'left' => 5, 'right' => 6],
    ['id' => 5, 'left' => 8, 'right' => 13],
    ['id' => 6, 'left' => 9, 'right' => 10],
    ['id' => 7, 'left' => 11, 'right' => 12],
];

/** @var TraverseLeftRightTree<array{id: int, left: int, right: int}> $traverse */
$traverse = new TraverseLeftRightTree();

$traverse(
    $tree,
    'left',
    'right',
    static function (array $node): void {
        echo sprintf('Processing node %s%s', $node['id'], PHP_EOL);
    },
    static function (array $node): void {
        echo sprintf('Childrens of node %s have been processed%s', $node['id'], PHP_EOL);
    },
);
Processing node 1
Processing node 2
Processing node 3
Childrens of node 3 have been processed
Processing node 4
Childrens of node 4 have been processed
Childrens of node 2 have been processed
Processing node 5
Processing node 6
Childrens of node 6 have been processed
Processing node 7
Childrens of node 7 have been processed
Childrens of node 5 have been processed
Childrens of node 1 have been processed

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-2.1-or-later
  • 更新时间: 2024-02-16