@@ -1042,42 +1042,46 @@ function get_full_month_time($start_time, $end_time)
1042
1042
}
1043
1043
}
1044
1044
1045
- /**
1046
- * 无限极非递归生成树
1047
- *
1048
- * @param array $items 例如:[['id' => 1, 'pid' => 0, 'name' => 'AA'],['id' => 2, 'pid' => 1, 'name' => 'BB']]
1049
- * @return array
1050
- */
1051
- function generateTree ($ items )
1052
- {
1053
- $ tree = [];
1054
- foreach ($ items as $ item ) {
1055
- if (isset ($ items [$ item ['pid ' ]])) {
1056
- $ items [$ item ['pid ' ]]['son ' ][] = &$ items [$ item ['id ' ]];
1057
- } else {
1058
- $ tree [] = &$ items [$ item ['id ' ]];
1045
+ if (!function_exists ('generate_tree ' )) {
1046
+ /**
1047
+ * 无限极非递归生成树
1048
+ *
1049
+ * @param array $items 例如:[1=>['id' => 1, 'pid' => 0, 'name' => 'AA'],2=>['id' => 2, 'pid' => 1, 'name' => 'BB']] key值必须和id值保持一致
1050
+ * @return array
1051
+ */
1052
+ function generate_tree ($ items )
1053
+ {
1054
+ $ tree = [];
1055
+ foreach ($ items as $ item ) {
1056
+ if (isset ($ items [$ item ['pid ' ]])) {
1057
+ $ items [$ item ['pid ' ]]['son ' ][] = &$ items [$ item ['id ' ]];
1058
+ } else {
1059
+ $ tree [] = &$ items [$ item ['id ' ]];
1060
+ }
1059
1061
}
1060
- }
1061
1062
1062
- return $ tree ;
1063
+ return $ tree ;
1064
+ }
1063
1065
}
1064
1066
1065
- /**
1066
- * 动态添加数据
1067
- *
1068
- * @param array $items 例如:[['id' => 1, 'pid' => 0, 'name' => 'AA'],['id' => 2, 'pid' => 1, 'name' => 'BB']]
1069
- * @param int $pid
1070
- * @param string $name
1071
- */
1072
- function addTree (&$ items , $ pid , $ name )
1073
- {
1074
- $ num = count ($ items ) + 1 ;
1075
- if ($ num == 0 ) {
1076
- $ num = 0 ;
1067
+ if (!function_exists ('add_tree ' )) {
1068
+ /**
1069
+ * 动态添加数据
1070
+ *
1071
+ * @param array $items 例如:[1=>['id' => 1, 'pid' => 0, 'name' => 'AA'],2=>['id' => 2, 'pid' => 1, 'name' => 'BB']] key值必须和id值保持一致
1072
+ * @param int $pid
1073
+ * @param string $name
1074
+ */
1075
+ function add_tree (&$ items , $ pid , $ name )
1076
+ {
1077
+ $ num = count ($ items ) + 1 ;
1078
+ if ($ num == 0 ) {
1079
+ $ num = 0 ;
1080
+ }
1081
+ $ items [$ num ] = [
1082
+ 'id ' => $ num ,
1083
+ 'pid ' => $ pid ,
1084
+ 'name ' => $ name ,
1085
+ ];
1077
1086
}
1078
- $ items [$ num ] = [
1079
- 'id ' => $ num ,
1080
- 'pid ' => $ pid ,
1081
- 'name ' => $ name ,
1082
- ];
1083
- }
1087
+ }
0 commit comments