A PHP tree-structured data access instance class for fast access to tree-structured data, adding subnodes, adding nodes to the index, getting references to itself, converting the tree object to an array, filtering _parent and other fields to avoid infinite loops, Arranges the two-dimensional array in ascending or descending order according to the specified key name.
< Span style= "padding:0px; margin:0px; Color:rgb (0, 0, 0); Font-family:consolas, "line-height:14px;background-color: #FFFFFF;font-size:14px;"; " >
< Span style= "padding:0px; margin:0px; Color:rgb (0, 0, 0); Font-family:consolas, "line-height:14px;background-color: #FFFFFF;font-size:14px;"; " >
First download the PHP tree structure data Access Instance class library that we need to use in this lesson: http://www.php.cn/xiazai/leiku/572
After the download, find the PHP class files we need, unzip to our local directory, create a new PHP file!
Once this is done, we will invoke this class in the new PHP file, and instantiate the class:
<?phpinclude_once "tree.php";//Introduction class file//definition array $arr = 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 ' =& Gt 4, ' name ' = ' php2 ', ' path ' = ' 1-4 '), $obj = new Tree ($arr); Instantiate $obj->getchild (2);p Rint_r ($obj->getchild (2));//Print result?>
< Span style= "padding:0px; margin:0px; Color:rgb (0, 0, 0); Font-family:consolas, "line-height:14px;background-color: #FFFFFF;font-size:14px;"; " > run the file and get the result as shown:
< Span style= "padding:0px; margin:0px; Color:rgb (0, 0, 0); Font-family:consolas, "line-height:14px;background-color: #FFFFFF;font-size:14px;"; " >