【发布时间】:2015-08-09 17:14:19
【问题描述】:
我有这个数组:
Array
(
[0] => Array
(
[id] => 1
[name] => Something
[other_id] => 2
[other_name] => One
)
[1] => Array
(
[id] => 1
[name] => Something
[other_id] => 3
[other_name] => Two
)
[2] => Array
(
[id] => 1
[name] => Something
[other_id] => 3
[other_name] => Three
)
[3] => Array
(
[id] => 1
[name] => Something
[other_id] => 2
[other_name] => Four
)
)
现在我需要数组看起来像这样:
Array
(
[0] => Array
(
[id] => 1
[name] => Something
[0] => Array
(
[other_id] => 2
[other_name] => One
)
[1] => Array
(
[other_id] => 3
[other_name] => Two
)
[2] => Array
(
[other_id] => 4
[other_name] => Three
)
)
)
我尝试了不同的方法,但没有结果。我希望有人可以帮助我一点。
【问题讨论】:
-
向我们展示一些努力。
-
一些问题:(1)所有
id总是一样的吗? (2) 您会考虑使用id作为数组中的键吗?这将大大简化代码。 -
不,id 更改。基本上我需要类似的东西:jsfiddle.net/LkjL2584
-
我接受它,然后你不使用任何特别的键,所以我可以将它们设置为我想要的任何东西。
-
等等...这对我来说没有意义。在输入中,您有
other_id, other_name组合2, One、3, Two、3, Three和2, Four。在输出中有2, One、3, Two和4, Three。这里有什么规则?