PHP uses the idea of transferring references to implement unlimited classification in Simpla, and uses the idea of transferring references to PHP to implement unlimited classification, this classification mode can be perfectly displayed.
The specific implementation code is as follows: if there is an error or a better method, you may want to communicate with each other.
Id pid name1 0 Sichuan 2 0 Chongqing 3 1 Chengdu 4 1 Mianyang 5 3 hi-tech zone
/*** Convert an array into an infinite classification-transmit the reference idea * @ param array $ items * @ return array */public static function get_tree ($ orig) {// solve the problem that subscript is not from 1 $ items = array (); foreach ($ orig as $ key => $ value) {$ items [$ value ['id'] = $ value;} // Start Assembly $ tree = array (); foreach ($ items as $ key => $ item) {if ($ item ['pid '] = 0) {// if the value is 0, $ tree [] = & $ items [$ key];} else {if (isset ($ items [$ item ['pid ']) {// if a value exists, it is a second-level classification. $ items [$ item ['pid '] ['child'] [] = & $ items [$ key]; // direct value assignment and change for transferring references} else {// at least three levels of classification // because it is a reference transfer idea, $ tree [] = & $ items [$ key] ;}} return $ tree ;}