当前位置:网站首页>PHP processing tree and infinite processing
PHP processing tree and infinite processing
2022-07-27 01:57:00 【Chenqing Nuo language】
/**
* Merging of arrays , And plus html Identification prefix
* @param array $data
* @param int $pid
* @param string $html
* @param int $level
* @return array
*/
public function treeLevel(array $data, $pid = 0, $html = '---', $level = 0) {
static $arr = [];
foreach ($data as $val) {
if ($pid == $val['pid']) {
// How many times to repeat a character
$val['html'] = str_repeat($html, $level * 2);
$val['level'] = $level + 1;
$arr[] = $val;
$this->treeLevel($data, $val['id'], $html, $val['level']);
}
}
return $arr;
}
/**
* Data Multilevel
* @param array $data
* @param int $pid
* @return array
*/
public function subTree($data, $pid = 0) {
// The result returned
$arr = [];
foreach ($data as $val) {
// A given PID Is the superior of the current record ID
if ($pid == $val['pid']) {
// recursive
$val['sub'] = $this->subTree($data,$val['id']);
$arr[] = $val;
}
}
return $arr;
}边栏推荐
- 25pxe efficient batch network installation
- HarmonyOS图像处理应用开发实战直播笔记
- Shell programming specifications and variables
- 项目 | 实现一个高并发内存池
- 数组的定义
- Small project - self connected campus network
- 39 installing LNMP
- 22FTP
- Excel changes the format of scientific counting method into text
- Share 29 chrome plug-ins, and there is always one for you
猜你喜欢

Machine learning exercise 6 - Support Vector Machines

iptables

IO function of standard C library

Review of wireless sensor networks (Bilingual)

Shell编程规范与变量

【CANN训练营】走进媒体数据处理1

Installation and basic operation of docker

Deveco could not resolve com.huawei.ohos:hap:2.4.5.0. error

Text three swordsman two

21dns domain name resolution
随机推荐
负载均衡的运用
Homework 1-4 learning notes
Share 29 chrome plug-ins, and there is always one for you
Docter的安装和基础操作
MySQL index
Harmonyos image processing application development live broadcast notes
mysql视图
25PXE高效批量网络装机
【无标题】
Proxmox VE安装与初始化
DevEco-Could not resolve com.huawei.ohos:hap:2.4.5.0.错误
MySQL multi table query
GDB的使用
CEPH (distributed storage)
39 installing LNMP
标准C库的IO函数
Makefile
27shell conditional statement
Paddleocr usage example
Application of load balancing