Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
meibuyu-rpc
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
without authentication
meibuyu-rpc
Commits
247b3b97
Commit
247b3b97
authored
May 08, 2020
by
王源
🎧
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加list_go_tree
parent
aa5e9f8e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
12 deletions
+20
-12
functions.php
src/functions.php
+20
-12
No files found.
src/functions.php
View file @
247b3b97
...
...
@@ -310,25 +310,33 @@ if (!function_exists('get_tree_id')) {
}
}
if
(
!
function_exists
(
'
get
_tree'
))
{
if
(
!
function_exists
(
'
list_go
_tree'
))
{
/**
* 树状的算法
* @param array $array 代转化数组
* @param int $pid 起始节点
* 列表转树状格式
* @param array $list
* @param string $pk
* @param string $pid
* @param string $children
* @return array
*/
function
get_tree
(
$array
=
[],
$pid
=
0
)
function
list_go_tree
(
array
$list
=
[],
$pk
=
'id'
,
$pid
=
'parent_id'
,
$children
=
'children'
)
{
$list
=
[];
// 获取每个节点的直属子节点,*记住是直属,不是所有子节点
foreach
(
$array
as
$item
)
{
if
(
isset
(
$list
[
$item
[
'pid'
]]))
{
$list
[
$item
[
'pid'
]][]
=
$item
;
$tree
=
$refer
=
[];
// 创建基于主键的数组引用
foreach
(
$list
as
$key
=>
$data
)
{
$refer
[
$data
[
$pk
]]
=
&
$list
[
$key
];
}
foreach
(
$list
as
$key
=>
$data
)
{
$parentId
=
$data
[
$pid
];
// 判断是否存在parent
if
(
isset
(
$refer
[
$parentId
]))
{
$parent
=
&
$refer
[
$parentId
];
$parent
[
$children
][]
=
&
$list
[
$key
];
}
else
{
$
list
[
$item
[
'pid'
]]
=
[
$item
];
$
tree
[]
=
&
$list
[
$key
];
}
}
return
format_tree
(
$list
)
;
return
$tree
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment