Array:
Copy code The code is as follows:
$items = array(
array('id' => 1, 'pid' => 0, 'name' => 'Level 11' ),
array('id' => 11, 'pid' => 0, 'name' => 'www .jb51.net Level 12' ),
array('id' => 2, 'pid' => 1, 'name' => 'Level 21' ),
array(' id' => 10, 'pid' => 11, 'name' => 'Level 22' ),
array('id' => 3, 'pid' => 1, ' name' => 'Level 23' ),
array('id' => 12, 'pid' => 11, 'name' => 'Level 24' ),
array ('id' => 13, 'pid' => 12, 'name' => 'Level 3 31' ),
array('id' => 9, 'pid' => 1 , 'name' => 'Level 25' ),
);
Function:
Copy code The code is 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 whether there is a sub -array
$ TEM && $ v v;
}
}
return $arr;
}
http://www.bkjia.com/PHPjc/736833.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/736833.htmlTechArticleArray: Copy the code as follows: $items = array( array('id' = 1, 'pid' = 0, 'name' = 'Level 11' ), array('id' = 11, 'pid' = 0, 'name' = 'www.jb51.net Level 12' ), array('id' =. ..