一段php树状数组 如何简化
下面是一段非常复杂的树状数组
如何提取所有的[name]值, 按倒序简化保存到一个一维数组
Array
(
[0] => Array
(
[id] => 1
[pid] =>
[name] => admin
[children] => Array
(
[0] => Array
(
[id] => 58
[pid] => 1
[name] => 000c
[children] => Array
(
[0] => Array
(
[id] => 72
[pid] => 58
[name] => 000c1
[children] => Array
(
[0] => Array
(
[id] => 93
[pid] => 72
[name] => 000c11
)
[1] => Array
(
[id] => 96
[pid] => 72
[name] => 000c12
)
)
)
[1] => Array
(
[id] => 81
[pid] => 58
[name] => 000c2
[children] => Array
(
[0] => Array
(
[id] => 99
[pid] => 81
[name] => 000c21
)
[1] => Array
(
[id] => 101
[pid] => 81
[name] => 000C22
)
)
)
[2] => Array
(
[id] => 87
[pid] => 58
[name] => 000c3
[children] => Array
(
[0] => Array
(
[id] => 104
[pid] => 87
[name] => 000C31
)
[1] => Array
(
[id] => 108
[pid] => 87
[name] => 000C32
)
)
)
)
)
[1] => Array
(
[id] => 44
[pid] => 1
[name] => ???
)
[2] => Array
(
[id] => 45
[pid] => 1
[name] => ??
)
[3] => Array
(
[id] => 46
[pid] => 1
[name] => ??
)
[4] => Array
(
[id] => 49
[pid] => 1
[name] => only
)
[5] => Array
(
[id] => 52
[pid] => 1
[name] => 007?
)
[6] => Array
(
[id] => 53
[pid] => 1
[name] => 0001e
[children] => Array
(
[0] => Array
(
[id] => 54
[pid] => 53
[name] => 000e1
[children] => Array
(
[0] => Array
(
[id] => 130
[pid] => 54
[name] => 000e11
)
[1] => Array
(
[id] => 131
[pid] => 54
[name] => 000e12
)
)
)
[1] => Array
(
[id] => 73
[pid] => 53
[name] => 000e2
[children] => Array
(
[0] => Array
(
[id] => 125
[pid] => 73
[name] => 000e21
[children] => Array
(
[0] => Array
(
[id] => 154
[pid] => 125
[name] => gfhgfhgf
)
[1] => Array
(
[id] => 155
[pid] => 125
[name] => hgfhgf
)
[2] => Array
(
[id] => 156
[pid] => 125
[name] => fghfgh
[children] => Array
(
[0] => Array
(
[id] => 157
[pid] => 156
[name] => fghfghf
)
[1] => Array
(
[id] => 158
[pid] => 156
[name] => hgfghff
)
[2] => Array
(
[id] => 159
[pid] => 156
[name] => rygfgfg
)
[3] => Array
(
[id] => 160
[pid] => 156
[name] => dgdfgd
[children] => Array
(
[0] => Array
(
[id] => 161
[pid] => 160
[name] => ghgjhgjh
)
[1] => Array
(
[id] => 162
[pid] => 160
[name] => ghfhgfhgf
)
[2] => Array
(
[id] => 163
[pid] => 160
[name] => ghfhgfgh
)
)
)
)
)
[3] => Array
(
[id] => 164
[pid] => 125
[name] => 000e211
)
)
)
[1] => Array
(
[id] => 126
[pid] => 73
[name] => 000e22
[children] => Array
(
[0] => Array
(
[id] => 136
[pid] => 126
[name] => rtyrtyrtyr
)
[1] => Array
(
[id] => 137
[pid] => 126
[name] => fghfghfhgf
)
[2] => Array
(
[id] => 138
[pid] => 126
[name] => fdgfdgfd
)
[3] => Array
(
[id] => 139
[pid] => 126
[name] => dfdgfd
)
[4] => Array
(
[id] => 140
[pid] => 126
[name] => fghfhgfg
)
[5] => Array
(
[id] => 141
[pid] => 126
[name] => hgfhgfhf
)
[6] => Array
(
[id] => 142
[pid] => 126
[name] => gfhfghfhgf
)
[7] => Array
(
[id] => 143
[pid] => 126
[name] => ghfghff
)
[8] => Array
(
[id] => 144
[pid] => 126
[name] => fghfhgf
)
)
)
)
)
)
)
)
)
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用array_walk_recursive 递归处理数组元素, 并使用array_reverse翻转得到一维数组:
下面拓展一个以id排序的方法, 仅供参考:
http://www.tiyee.net/post/151
想说你这个数组真hentai....、