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( 'id' => 1, 'name' => 'php', 'path' => '1' ), array( 'id' => 3, 'name' => 'php1', 'path' => '1-3' ), array( 'id' => 2, 'name' => 'mysql', 'path' => '2' ), array( 'id' => 6, 'name' => 'mysql1', 'path' => '2-6' ), array( 'id' => 7, 'name' => 'mysql2', 'path' => '2-7' ), array( 'id' => 5, 'name' => 'php11', 'path' => '1-3-5' ), array( 'id' => 4, 'name' => 'php2', 'path' => '1-4' ), ); $obj = new Tree($arr); //实例化 $obj->getChild(2); print_r($obj->getChild(2));//打印结果 ?>
Run the file and the result will be as shown below:
#
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!