Analysis of the development process of PHP tree structure data Access instance

Source: Internet
Author: User
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;"; " >

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.