PHP-通过他们的孩子的链阵列项目
我在PHP中有以下各种项目:
0 => [
'name' => 'retail',
'id' => 1,
'following' => null
],
1 => [
'name' => 'industry',
'id' => 2,
'following' => 3
],
2 => [
'name' => 'entertainment',
'id' => 3,
'following' => 1
],
3 => [
'name' => 'sports',
'id' => 4,
'following' => null
],
4 => [
'name' => 'construction',
'id' => 5,
'following' => null
],
5 => [
'name' => 'music',
'id' => 6,
'following' => 5
]
...
我想链接每个项目的名称,并从父母到孩子的订购。上面的示例将给出结果:
[
0 => 'industry / entertainment / retail',
1 => 'sports',
2 => 'music / construction'
]
每个项目都可以拥有尽可能多的孩子,并且订单或项目是随机的。从几天开始,我正在研究这个问题,但我仍然没有成功。有帮助吗?
I have the following array of items in PHP :
0 => [
'name' => 'retail',
'id' => 1,
'following' => null
],
1 => [
'name' => 'industry',
'id' => 2,
'following' => 3
],
2 => [
'name' => 'entertainment',
'id' => 3,
'following' => 1
],
3 => [
'name' => 'sports',
'id' => 4,
'following' => null
],
4 => [
'name' => 'construction',
'id' => 5,
'following' => null
],
5 => [
'name' => 'music',
'id' => 6,
'following' => 5
]
...
and I would like to chain the names of each items and ordering them from parent to child. The example above would give the result :
[
0 => 'industry / entertainment / retail',
1 => 'sports',
2 => 'music / construction'
]
Each item could have as many as child as possible, and the order or the items is random. I am working on this since a few days and I have still no success. Any help please ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
pollowings
作为id的数组ID:[plost_id]
followings
as an array ofid: [following_id]
followings
recursively