In some complex systems, infinite levels of classification of information columns are required to enhance the flexibility of the system. Recursion, simply put, is the repeated calling of a piece of program code. When the code is written into a custom function, parameters and other variables are saved, and the function is repeatedly called until a certain condition is reached before jumping out and returning the corresponding data. So how does PHP achieve infinite classification?
First step: download the PHP recursive implementation infinite classification library we need to use in this lesson: http://www.php.cn/xiazai/leiku/292
Step 2: After the download is completed, find the php class file, extract it to the local server, and create a new php file!
Step 3: We call this class in this new file and instantiate this class:
<?php include_once "cate.php";//引入类文件 $obj = new Category; //实例化 $obj->unlimitedForLayer($cate); var_dump($obj->unlimitedForLayer($cate)); //var_dump($obj->unlimitedForLevel($cate)); //var_dump($obj->getParents($cate,7)); //var_dump($obj->getChildsId($cate,2)); //var_dump($obj->getChilds($cate,2)); ?>
The running results are as shown below:
The above is the detailed content of The development process and sample code of php recursive implementation of infinite classification. For more information, please follow other related articles on the PHP Chinese website!