按二级键对包含单元素关联行的数组进行分组,以形成索引元素的关联数组
我有一个数组,其中包含数据如下:
[
0 => ['www.google.com' => 'www.google.com/a'],
1 => ['www.google.com' => 'www.google.com/a'],
2 => ['www.test.com' => 'www.test.com'],
5 => ['www.test.com' => 'www.test.com/c'],
]
我需要对特定 url 的所有链接进行分组,如下所示:
Array (
[www.google.com] => Array (
[0] => www.google.com/a
[1] => www.google.com/a
)
[www.test.com] => Array (
[0] => www.test.com
[1] => www.test.com/c
)
)
I have an array, which contains data as follows:
[
0 => ['www.google.com' => 'www.google.com/a'],
1 => ['www.google.com' => 'www.google.com/a'],
2 => ['www.test.com' => 'www.test.com'],
5 => ['www.test.com' => 'www.test.com/c'],
]
I need to group all links for particular url like this:
Array (
[www.google.com] => Array (
[0] => www.google.com/a
[1] => www.google.com/a
)
[www.test.com] => Array (
[0] => www.test.com
[1] => www.test.com/c
)
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我们调用第一个数组
$domains
。这可能有用...
If we call the first array
$domains
.That might work...
只需使用两个循环来访问嵌套的关联元素,并按二级键对数据进行分组,同时将值推入子数组中。 演示
输出:
Simply use two loops to access the nested associative elements and group the data by second level keys while pushing the values into subarrays. Demo
Output: