The following is a description of the PHP infinite Classification of code, I hope to help everyone, let's have a look
function GenTree5 ($items) {foreach ($items as $item) $items [$item [' pid ']][' son '] [$item [' id ']] = & $items [$it em[' id ']; return Isset ($items [0][' son '])? $items [0][' son ']: Array ();} function GenTree7 ($items) {$tree = array ();//Well-formatted tree foreach ($items as $item) if (Isset ($items [$item [' PID '] ]) $items [$item [' pid ']][' son '] [] = & $items [$item [' id ']]; else $tree [] = & $items [$item [' id ']]; return $tree;} $items = Array (1 = = Array (' id ' = = 1, ' pid ' = 0, ' name ' = ' Jiangxi '), 2 = = Array (' id ' = = 2, ' pid ' =& Gt 0, ' name ' = ' Heilongjiang Province '), 3 = = Array (' id ' = 3, ' pid ' = = 1, ' name ' = ' Nanchang '), 4 = = Array (' id ' = = 4, ' pid ' = 2, ' name ' = ' Harbin '), 5 = = Array (' id ' = 5, ' pid ' = = 2, ' name ' = ' Jixi '), 6 = = Array ( ' id ' = 6, ' pid ' = 4, ' name ' = ' Xiangfang District '), 7 = = Array (' id ' = = 7, ' pid ' = 4, ' name ' = ' Nangang '), 8 = = Array (' id ' = = 8, ' pid ' = + 6, ' Name ' = = ' and Hing Road '), 9 = = Array (' id ' = = 9, ' pid ' = 7, ' name ' = ' West big straight Street '), and array (' id ' = 10, ' pid ' = 8, ' name ' = ' Northeast Forestry University '), one by one and array (' id ' = = ', ' pid ' = 9, ' name ' = ' Harbin Institute of Technology '), =&G T Array (' id ' = +, ' pid ' = + 8, ' name ' = ' harbin Normal University '), and array (' id ' = ' + ', ' pid ' = 1, ' name ' = ' Ganzhou '), + = array (' id ' = +, ' pid ' = ' = ') ', ' name ' = ' Gan County '), and array (' id ' = ' + ', ' pid ' = The ' name ' = ' Yudu County '), and the array (' id ' = ' + ', ' pid ' = ' + ', ' name ' = ' Mao Dian zhen '), + = array (' ID ' => ; The ' pid ' = +, ' name ' + ' Ota township ', and Array (' id ' = ' + ', ' pid ' = + ', ' name ' = ' yi Yuan cun '), Array (' id ' = +, ' pid ' = +, ' name ' = ' Shang Ba village '),;p Rint_r (GenTree5 ($items));p Rint_r (GenTree7 ($items));