关于xuzuning版主发的非递归树形数组构造函数问题
之前自己使用过循环或者递归构建树型数组。今天搜索的时候看到之前xuzuning版主发的非递归树型数组构建函数。
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
/**
* 创建子节点树形数组
* 参数
* $ar 数组,邻接列表方式组织的数据
* $id 数组中作为主键的下标或关联键名
* $pid 数组中作为父键的下标或关联键名
* 返回 多维数组
**/
function find_child($ar, $id='id', $pid='pid') {
foreach($ar as $v) $t[$v[$id]] = $v;
foreach ($t as $k => $item){
if( $item[$pid] ) {
$t[$item[$pid]]['child'][$item[$id]] =& $t[$k];
}
}
return $t;
}
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号