php网站开发中使用递归的例子有哪些?能否提供实例代码。谢谢 php网站开发中使用递归的例子有哪些?能否提供实例代码。谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 无限分类copy 来的代码 <?php$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 ));function findChild(&$arr,$id){ $childs=array(); foreach ($arr as $k => $v){ if($v['parentid']== $id){ $childs[]=$v; } } return $childs;}function build_tree($root_id){ global $rows; $childs=findChild($rows,$root_id); if(empty($childs)){ return null; } foreach ($childs as $k => $v){ $rescurTree=build_tree($v[id]); if( null != $rescurTree){ $childs[$k]['childs']=$rescurTree; } } return $childs;}$tree=build_tree(0);echo memory_get_usage();print_r($tree);?> 问关于sql语句防止用户重复提交有时候不起作用 有啥方法及软件可以编辑JS 有多少人在使用MVC框架开发程序? 关于php类的继承的问题,请大家帮帮忙,一直困在这里了 怎样表示树比较好 对 MySQL 的 SHOW TABLE STATUS 满足来自site 和cookie为空 两个条件 才赋予新cookie PHp+js的灯片的循环请大侠帮忙改进 fopen()函数 r r+到底有啥区别啊? php 关于数字的单独调用 求伪静态 二级域名 httpd.ini写法 怎么用正则判断如下代码??
copy 来的代码 <?php
$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
)
);function findChild(&$arr,$id){
$childs=array();
foreach ($arr as $k => $v){
if($v['parentid']== $id){
$childs[]=$v;
}
}
return $childs;
}
function build_tree($root_id){
global $rows;
$childs=findChild($rows,$root_id);
if(empty($childs)){
return null;
}
foreach ($childs as $k => $v){
$rescurTree=build_tree($v[id]);
if( null != $rescurTree){
$childs[$k]['childs']=$rescurTree;
}
}
return $childs;
}$tree=build_tree(0);
echo memory_get_usage();
print_r($tree);?>