我是靠谱客的博主 动人黄豆,这篇文章主要介绍tp5 php array_merge合并函数array_column(id值不见)处理办法(创建合成合拼数组)(foreach 记录集)取值方式一:使用array_merge函数$data_1_t = array_merge($data_1_t,array_column($menu_list_1,'title','id'));取值方式二:使用+号$data_1_t = $data_1_t + array_column($menu_list_1,'title','id');,现在分享给大家,希望可以做个参考。
例子:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77$data_0=[];$data_1=[];$data_2=[];$data_3=[]; $data_1_t=[];$data_2_t=[];$data_3_t=[]; $res = Db::name('menu') ->field('id as value,title as name,pid,controller,position,hide_banner,model,url,img') ->where('deleted',0) ->where('hide',0) ->whereNull('pid') ->order('sort desc,id desc') ->select(); if(!empty($res)){ $count = count($res); foreach($res as $k => $rs){ $rs['children']=getMenuData($rs['value'],'menu',1); $res[$k]= $rs; //生成前端各栏目的分类 //一级 $menu_list_1 = Db::name('menu') ->field('id,title') ->where('pid',$rs['value']) ->where('deleted',0) ->where('level',1) ->order('sort desc,id desc') ->select(); if(!empty($menu_list_1)){ $data_1[$rs['value']]=array_column($menu_list_1,null,'id'); $data_1_t = array_merge($data_1_t,array_column($menu_list_1,'title','id')); // $data_1_t = $data_1_t + array_column($menu_list_1,'title','id'); foreach($menu_list_1 as $v1){ //2级 $menu_list_2 = Db::name('menu') ->field('id,title') ->where('pid',$v1['id']) ->where('deleted',0) ->where('level',2) ->order('sort desc,id desc') ->select(); if(!empty($menu_list_2)){ $data_2[$v1['id']]=array_column($menu_list_2,null,'id'); //$data_2_t = array_merge($data_2_t,array_column($menu_list_2,null,'id')); $data_2_t = $data_2_t + array_column($menu_list_2,'title','id'); foreach($menu_list_2 as $v2){ //3级 $menu_list_3 = Db::name('menu') ->field('id,title') ->where('pid',$v2['id']) ->where('deleted',0) ->where('level',3) ->order('sort desc,id desc') ->select(); if(!empty($menu_list_3)){ $data_3[$v2['id']]=array_column($menu_list_3,null,'id'); //$data_3_t = array_merge($data_3_t,array_column($menu_list_3,null,'id')); $data_3_t = $data_3_t + array_column($menu_list_3,'title','id'); foreach($menu_list_3 as $v3){ //4级 $menu_list_4 = Db::name('menu') ->field('id,title') ->where('pid',$v3['id']) ->where('deleted',0) ->where('level',4) ->order('sort desc,id desc') ->select(); if(!empty($menu_list_4)){ $data_4[$v3['id']]=array_column($menu_list_4,null,'id'); } } } } } } } } //0 顶级 $data_0 = array_column($res, 'name','value'); }
结果:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365{ "code": 200, "msg": "成功", "count": 12, "data": { "data_0": { "1": "首页", "3": "直播课程", "4": "录播课程", "5": "在线题库", "6": "团队", "7": "资讯", "8": "商城", "9": "论坛", "11": "新手指南", "12": "帮助中心", "14": "关于我们1", "18": "在线招聘" }, "data_1": { "3": { "25": { "id": 25, "title": "自考" }, "26": { "id": 26, "title": "教师" } }, "4": { "33": { "id": 33, "title": "教师1" }, "34": { "id": 34, "title": "自考1" } }, "5": { "39": { "id": 39, "title": "自考" }, "40": { "id": 40, "title": "人力" }, "41": { "id": 41, "title": "教师" } }, "6": { "51": { "id": 51, "title": "会计" }, "52": { "id": 52, "title": "教师" }, "53": { "id": 53, "title": "人力" } }, "7": { "57": { "id": 57, "title": "公司新闻" }, "58": { "id": 58, "title": "行业新闻" }, "59": { "id": 59, "title": "公告" } }, "8": { "60": { "id": 60, "title": "计算机" }, "61": { "id": 61, "title": "自考" } }, "11": { "65": { "id": 65, "title": "请修改标题" }, "66": { "id": 66, "title": "请修改标题" }, "67": { "id": 67, "title": "意见反馈" }, "68": { "id": 68, "title": "VIP购买" }, "69": { "id": 69, "title": "疑难问答" }, "70": { "id": 70, "title": "交流社区" } }, "12": { "71": { "id": 71, "title": "请修改标题" }, "72": { "id": 72, "title": "发布须知" }, "73": { "id": 73, "title": "新手入门" }, "74": { "id": 74, "title": "注册账号" }, "75": { "id": 75, "title": "如何支付" } }, "14": { "79": { "id": 79, "title": "联系方式" }, "80": { "id": 80, "title": "关于我们" } }, "18": { "76": { "id": 76, "title": "文职类招聘" }, "77": { "id": 77, "title": "市场部招聘" }, "78": { "id": 78, "title": "技术部招聘" } } }, "data_1_t": [ "教师", "自考", "自考1", "教师1", "教师", "人力", "自考", "人力", "教师", "会计", "公告", "行业新闻", "公司新闻", "自考", "计算机", "交流社区", "疑难问答", "VIP购买", "意见反馈", "请修改标题", "请修改标题", "如何支付", "注册账号", "新手入门", "发布须知", "请修改标题", "技术部招聘", "市场部招聘", "文职类招聘", "关于我们", "联系方式" ], "data_2": { "25": { "29": { "id": 29, "title": "本科" }, "30": { "id": 30, "title": "专科" } }, "26": { "27": { "id": 27, "title": "小学" }, "28": { "id": 28, "title": "中学" } }, "33": { "37": { "id": 37, "title": "中学2" }, "38": { "id": 38, "title": "小学2" } }, "34": { "35": { "id": 35, "title": "研究生" }, "36": { "id": 36, "title": "博士" } }, "39": { "47": { "id": 47, "title": "行管专科" }, "48": { "id": 48, "title": "行管本科" } }, "40": { "45": { "id": 45, "title": "小学1" }, "46": { "id": 46, "title": "中学1" } }, "41": { "42": { "id": 42, "title": "高中" }, "43": { "id": 43, "title": "中学" }, "44": { "id": 44, "title": "小学" } }, "51": { "56": { "id": 56, "title": "大专" } }, "52": { "55": { "id": 55, "title": "大专" } }, "53": { "54": { "id": 54, "title": "大专" } }, "60": { "63": { "id": 63, "title": "PHP教程" }, "64": { "id": 64, "title": "JS教程" } }, "61": { "62": { "id": 62, "title": "专科升本科密级" } } }, "data_2_t": { "27": "小学", "28": "中学", "29": "本科", "30": "专科", "35": "研究生", "36": "博士", "37": "中学2", "38": "小学2", "42": "高中", "43": "中学", "44": "小学", "45": "小学1", "46": "中学1", "47": "行管专科", "48": "行管本科", "54": "大专", "55": "大专", "56": "大专", "62": "专科升本科密级", "63": "PHP教程", "64": "JS教程" }, "data_3": { "28": { "32": { "id": 32, "title": "请修改标题" } }, "30": { "31": { "id": 31, "title": "请修改标题" } }, "44": { "49": { "id": 49, "title": "综合素质" }, "50": { "id": 50, "title": "教育知识与能力" } } }, "data_3_t": { "31": "请修改标题", "32": "请修改标题", "49": "综合素质", "50": "教育知识与能力" }, "data_4": null, "data_4_t": null } }
取值方式一:使用array_merge函数
$data_1_t = array_merge($data_1_t,array_column($menu_list_1,'title','id'));
array_merge函数,当ID=数字时,会整合去掉
取值方式二:使用+号
$data_1_t = $data_1_t + array_column($menu_list_1,'title','id');
最后
以上就是动人黄豆最近收集整理的关于tp5 php array_merge合并函数array_column(id值不见)处理办法(创建合成合拼数组)(foreach 记录集)取值方式一:使用array_merge函数$data_1_t = array_merge($data_1_t,array_column($menu_list_1,'title','id'));取值方式二:使用+号$data_1_t = $data_1_t + array_column($menu_list_1,'title','id');的全部内容,更多相关tp5内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复