Array:
Copy the Code code as follows:
$items = Array (
Array (' id ' = = 1, ' pid ' = + 0, ' name ' = ' 11 '),
Array (' id ' = = ' pid ' = 0, ' name ' = ' www.jb51.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 '),
);
Function:
Copy the Code code as follows:
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;
}
http://www.bkjia.com/PHPjc/736833.html www.bkjia.com true http://www.bkjia.com/PHPjc/736833.html techarticle array: Copy the code as follows: $items = array (' id ' = 1, ' pid ' = 0, ' name ' = ' one-step '), array (' id ' = all, ' pid ' = 0, ' name ' = ' www . jb51.net First Class, array (' id ' = ...