@ 2016-10-13T07:57:24Z <?php
$arrs = array( array('id'=>1,'name'=>'root','pid'=>0),
array('id'=>2,'name'=>'root1','pid'=>0),
array('id'=>3,'name'=>'level1','pid'=>1),
array('id'=>4,'name'=>'level11','pid'=>1),
array('id'=>5,'name'=>'leve21','pid'=>2),
array('id'=>6,'name'=>'level2','pid'=>2)
);
class digui{
function index($id,$arr){
echo $this->doarr($id,$arr);
}
private function doarr($id,$arr ){
foreach($arr as $key => $val){
if($id==$val['pid']){
if($val['pid']!=0)
{
$this->doarr($val['pid'],$arr);
return $val['name'];
}
else return $val['name'];
}
}
}
}
$d = new digui;
//$d->index(3,$arrs);
function test($a=0,&$result=array()){
$a++;
if ($a<10) {
$result[]=$a;
test($a,$result);
}
echo $a;
print_r($result);
return $result;
}
function test1($a=0){
static $result=array();
$a++;
if ($a<10) {
$result[]=$a;
test1($a);
print_r($result);
}
return $result;
}
$arrs = array( array('id'=>1,'name'=>'root','pid'=>0),
array('id'=>2,'name'=>'root1','pid'=>0),
array('id'=>3,'name'=>'level1','pid'=>1),
array('id'=>4,'name'=>'level11','pid'=>1),
array('id'=>5,'name'=>'leve21','pid'=>2),
array('id'=>6,'name'=>'level2','pid'=>2)
);
function getree($data,$pid){
$tree = array();
foreach($data as $key=>$val){
if($pid == $val['pid']){
$val['pid'] = getree($data,$val['id']);
$tree[] = $val;
}
}
return $tree;
}
function getree1($data,$pid){
$tree = array();
foreach($data as $key=>$val){
if($pid==$val['pid']){
$val['pid'] = getree1($data,$val['id']);
$tree[] = $val;
}
return $tree;
}
}
$res = getree1($arrs,0);
$rows = array(
array(
'id' => 1,
'name' => 'dev',
'parentid' => 0
),
array(
'id' => 2,
'name' => 'php',
'parentid' => 1
),
array(
'id' => 3,
'name' => 'smarty',
'parentid' => 2
),
array(
'id' => 4,
'name' => 'life',
'parentid' => 0
),
array(
'id' => 5,
'name' => 'pdo',
'parentid' => 2
),
array(
'id' => 6,
'name' => 'pdo-mysql',
'parentid' => 5
),
array(
'id' => 7,
'name' => 'java',
'parentid' => 1
)
);
// 72648
// 84072
function buildtree($rows,$root_id){
$childs = findchild($rows,0);
if(empty($childs) ) return null;
foreach($childs as $k=>$v){
$rescurtree = buildtree($rows,$v['id']);
if(!empty($rescurtree)){
$rescurtree[$k]['childs'] = $rescurtree;
}
}
return $rescurtree;
}
function findchild($rows,$id){
$childs = array();
foreach($rows as $k=>$v){
if($v['parentid']==$id)
$childs[] = $v;
}
return $childs;
}
buildtree($rows,0);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for git.master , rfc.property-hooks Fatal error: Out of memory (allocated 35651584 bytes) (tried to allocate 4096 bytes) in /in/MbklT on line 165
mmap() failed: [12] Cannot allocate memory
mmap() failed: [12] Cannot allocate memory
Process exited with code 255 . Output for git.master_jit Fatal error: Out of memory (allocated 18874368 bytes) (tried to allocate 4096 bytes) in /in/MbklT on line 165
mmap() failed: [12] Cannot allocate memory
mmap() failed: [12] Cannot allocate memory
Process exited with code 255 . This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.
Active branches Archived branches Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page
preferences:dark mode live preview
56.52 ms | 401 KiB | 8 Q