Array:
$items = Array (
Array (' id ' = = 1, ' pid ' = + 0, ' name ' = ' 11 '),
Array (' id ' = = ' pid ' = 0, ' name ' = ' www.111cn.net ' 12 '),
Array (' id ' = = 2, ' pid ' = + 1, ' name ' = ' two ' Level 21 '),
Array (' id ' = +, ' pid ' = ' = ', ' name ' = ' two ' 22 '),
Array (' id ' = = 3, ' pid ' = + 1, ' name ' = ' two ' level 23 '),
Array (' id ' = ' = ', ' pid ' = ' = ', ' name ' = ' two ' 24 '),
Array (' id ' = ' + ', ' pid ' = ' + ', ' name ' = ' three ', ' Level 31 '),
Array (' id ' = = 9, ' pid ' = + 1, ' name ' = ' two ' Level 25 '),
);
| The code is as follows |
| < td="">
|
Function:
function Formattree ($array, $pid = 0) {
$arr = Array ();
$tem = Array ();
foreach ($array as $v) {
if ($v [' pid '] = = $pid) {
$tem = Formattree ($array, $v [' id ']);
Determine if a subarray exists
$tem && $v [' son '] = $tem;
$arr [] = $v;
}
}
return $arr;
}
| The code is as follows |
| < td="">
|
Where the array must contain the ID and PID to specify the hierarchical relationship between the array values
Articles you may be interested in
- The implementation of infinite Classification & tree-type Forum
- PHP MySQL implements infinite class classification tree display classification relationship
- Unlimited categories of articles
- Unlimited classification
- The realization method of infinite classification and tree-type forum
- PHP Infinite Class classification code
- PHP Infinite Class Classification [recursive method]
- Infinite class Classification [pre-sorting traversal tree algorithm]
- An algorithm for infinite classification of PHP
- Ecshop Commodity Unlimited Class Code
http://www.bkjia.com/PHPjc/738522.html www.bkjia.com true http://www.bkjia.com/PHPjc/738522.html techarticle Array: The code is as follows $items = array (' id ' = 1, ' pid ' = 0, ' name ' = ' Level One '), array (' id ' = all, ' pid ' = 0, ' name ' = ' WWW.111CN . NET level '), array (' id ' = 2, ' pid ' = 1,...