当前位置:网站首页>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;
}边栏推荐
- Summary of key points of system dynamics specialized examination
- You can understand the detailed introduction and understanding of inheritance
- D - Difference HDU - 5936
- Web services (02) - Web server middleware
- DHCP experiment ideas
- 32 Three Musketeers sed
- GDB的使用
- Complete super detailed introduction to transactions in MySQL
- Application of load balancing
- mysql视图
猜你喜欢
随机推荐
Mysql数据库-面试题
[cann training camp] enter media data processing (Part 2)
Suggestions for beginners of MySQL (strongly recommended ~ don't regret ~ ~)
Notes during in-depth learning (to be improved)
MySQL backup recovery
MySQL single table query exercise
25pxe efficient batch network installation
Deveco could not resolve com.huawei.ohos:hap:2.4.5.0. error
MySQL common statements
【无标题】
Makefile
Shell script - backup, update and rollback of files
RT thread learning
[untitled]
Desktop solution summary
SSH and NFS services
【无标题】
32 Three Musketeers sed
Makefile
mysql视图
![[cann training camp] enter media data processing 1](/img/6c/76d3784203af18a7dee199c3a7fd24.png)








