当前位置:网站首页>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;
}边栏推荐
- How should CDC be configured for Oracle cluster mode? I can run normally in stand-alone mode, but I can't read the increment in cluster mode
- Use ECs and OSS to set up personal network disk
- PXE experiment
- Shell programming specifications and variables
- Shell (13) Three Musketeers
- Process and planned task management
- 无线传感器网络(双语)复习
- Vector容器的底层实现
- Definition of array
- Use of GDB
猜你喜欢
随机推荐
It's the first time to write your own program in C language. If you have a boss, you can help a little
mysql视图
Machine learning exercise 7 - K-means and PCA (principal component analysis)
识别神器Mx-yolov3
iptables
24SSH服务
云数据库管理初体验
29shell函数
Pyqt5 qtablewidget setting gives priority to the text on the right
Paddleocr usage example
D - Difference HDU - 5936
[polymorphism] the detailed introduction of polymorphism is simple and easy to understand
regular expression
Ubuntu12.10 installing mysql5.5 (III)
虚拟化技术KVM
MySQL stored procedure function
MySQL中对于事务完整的超详细介绍
CEPH (distributed storage)
MySQL single table query exercise
信息获取技术复习







