Download the PHP package clouds-flight/array-tree without Composer

On this page you can find all versions of the php package clouds-flight/array-tree. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package array-tree

array-tree

带有树结构的数组(含parent_id)非递归生成包含层级的树结构数组

只是遍历了一遍所有数据,和指定父元素及其下所有子元素,未使用递归,理论上可以支持无限层级

原始结构

json编码后结构如下:
   [{
       "id": "1",
       "parent_id": "0",
       "name": "插件中心"
   }, {
       "id": "2",
       "parent_id": "1",
       "name": "钩子管理"
   }, {
       "id": "3",
       "parent_id": "2",
       "name": "钩子插件管理"
   }, {
       "id": "4",
       "parent_id": "2",
       "name": "钩子插件排序"
   }, {
       "id": "5",
       "parent_id": "2",
       "name": "同步钩子"
   }, {
       "id": "6",
       "parent_id": "0",
       "name": "设置"
   }, {
       "id": "7",
       "parent_id": "6",
       "name": "友情链接"
   }, {
       "id": "8",
       "parent_id": "7",
       "name": "添加友情链接"
   }, {
       "id": "9",
       "parent_id": "7",
       "name": "添加友情链接提交保存"
   }]

生成包含层级结构的数组

ArrayTree::getTree($array,id);  //$array 包含树结构关系的数组(需包含 id  parent_id name),$id 父id ,会返回该父id下的所有子级元素(层级结构)
结果如下:
[{
    "id": "1",
    "parent_id": "0",
    "name": "插件中心",
    "children": [{
        "id": "2",
        "parent_id": "1",
        "name": "钩子管理",
        "children": [{
            "id": "3",
            "parent_id": "2",
            "name": "钩子插件管理",
            "children": []
        }, {
            "id": "4",
            "parent_id": "2",
            "name": "钩子插件排序",
            "children": []
        }, {
            "id": "5",
            "parent_id": "2",
            "name": "同步钩子",
            "children": []
        }]
    }]
    }, {
    "id": "6",
    "parent_id": "0",
    "name": "设置",
    "children": [{
        "id": "7",
        "parent_id": "6",
        "name": "友情链接",
        "children": [{
            "id": "8",
            "parent_id": "7",
            "name": "添加友情链接",
            "children": []
               }, {
            "id": "9",
            "parent_id": "7",
            "name": "添加友情链接提交保存",
            "children": []
        }]
    }]
}]

生成包含层级结构的数组,并添加名称路径

ArrayTree::getTreePath($res,$id,$separator);  //$array 包含树结构关系的数组(需包含 id  parent_id name),$id 父id ,会返回该父id下的所有子级元素(层级结构),$separator 路径分隔符
结果如下(分隔符是/,因转为json字符串添加了转义符,解码后是没有\的):
[{
    "id": "1",
    "parent_id": "0",
    "name": "插件中心",
    "path": "插件中心",
    "children": [{
        "id": "2",
        "parent_id": "1",
        "name": "钩子管理",
        "path": "插件中心\/钩子管理",
        "children": [{
            "id": "3",
            "parent_id": "2",
                "name": "钩子插件管理",
                "path": "插件中心\/钩子管理\/钩子插件管理",
                "children": []
               }, {
        "id": "4",
            "parent_id": "2",
            "name": "钩子插件排序",
            "path": "插件中心\/钩子管理\/钩子插件排序",
            "children": []
              }, {
            "id": "5",
            "parent_id": "2",
            "name": "同步钩子",
            "path": "插件中心\/钩子管理\/同步钩子",
            "children": []
        }]
    }]
        }, {
         "id": "6",
         "parent_id": "0",
        "name": "设置",
        "path": "设置",
        "children": [{
        "id": "7",
            "parent_id": "6",
            "name": "友情链接",
            "path": "设置\/友情链接",
            "children": [{
                "id": "8",
                "parent_id": "7",
                "name": "添加友情链接",
                "path": "设置\/友情链接\/添加友情链接",
                "children": []
                   }, {
                "id": "9",
                "parent_id": "7",
                "name": "添加友情链接提交保存",
                 path": "设置\/友情链接\/添加友情链接提交保存",
                "children": []
            }]
        }]
    }]

获取父元素所有子元素id的集合

ArrayTree::getChildrenIdArray($array,$id);  //$array 包含树结构关系的数组(需包含 id  parent_id name),$id 父id ,会返回该父id下的所有子级元素id的集合
结果如下:
["1","6","2","7","3","4","5","8","9"]

All versions of array-tree with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package clouds-flight/array-tree contains the following files

Loading the files please wait ....