Analysis of the development process of PHP tree structure data access examples

黄舟
Release: 2023-03-15 11:02:01
Original
1482 people have browsed it

A PHP tree structure data access instance class, used to quickly access tree structure data, add child nodes, add nodes to indexes, obtain references to themselves, convert Tree objects into arrays, and filter _parent and other fields to avoid causing an infinite loop, arrange the two-dimensional array in ascending or descending order according to the specified key name.


##First download the PHP tree structure data access instance class library we need to use in this course: http://www.php.cn/xiazai/leiku/572

Download completed Then find the php class file we need, unzip it to our local directory, and create a new php file!

After completion, we need to call this class in the new php file and instantiate the class:

<?php
include_once "tree.php";//引入类文件
//定义数组
$arr = array(
  array( &#39;id&#39; => 1, &#39;name&#39; => &#39;php&#39;, &#39;path&#39; => &#39;1&#39; ),
  array( &#39;id&#39; => 3, &#39;name&#39; => &#39;php1&#39;, &#39;path&#39; => &#39;1-3&#39; ),
   array( &#39;id&#39; => 2, &#39;name&#39; => &#39;mysql&#39;, &#39;path&#39; => &#39;2&#39; ),
   array( &#39;id&#39; => 6, &#39;name&#39; => &#39;mysql1&#39;, &#39;path&#39; => &#39;2-6&#39; ),
   array( &#39;id&#39; => 7, &#39;name&#39; => &#39;mysql2&#39;, &#39;path&#39; => &#39;2-7&#39; ),
   array( &#39;id&#39; => 5, &#39;name&#39; => &#39;php11&#39;, &#39;path&#39; => &#39;1-3-5&#39; ),
   array( &#39;id&#39; => 4, &#39;name&#39; => &#39;php2&#39;, &#39;path&#39; => &#39;1-4&#39; ),
   );

$obj = new Tree($arr); //实例化
$obj->getChild(2);
print_r($obj->getChild(2));//打印结果
?>
Copy after login

Run the file and the result will be as shown below:

Analysis of the development process of PHP tree structure data access examples#

The above is the detailed content of Analysis of the development process of PHP tree structure data access examples. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!