如何减少数组嵌套
基本上我的数组嵌套得太深了。它有三个子、子、子数组,我只想保留中间的一个。
我发现很难解释它,但我所拥有的是这样的:
"data": [
{
"order":
{
"id": "1,",
"mail": {
"mail1": "X";
"mail2": "X";
},
},
{
"id": "2,",
"amount": "X",
},
}
],
"data": [
{
"order": {
"id": "3,",
"amount": "X",
},
}
],
我需要删除第一个和最后一个子数组,所以我只得到一个巢:
[1] {
"id": "[email protected],",
"mail1": "X",
"mail2": "X",
},
[2] {
"id": "2,",
"amount": "X",
},
[3] {
"id": "3,",
"amount": "X",
},
我不知道这是否有意义。我确信这不是很难做到的,但我只设法创建了一个 foreach 来创建一个包含所有值的数组,但我丢失了所有子数组。
这是怎么做到的? (至少删除第一个数组)。
Basically my array is nested too deep. It has three sub,sub,sub arrays and I only want to keep the middle one.
I find it hard to explain it but what I have is this:
"data": [
{
"order":
{
"id": "1,",
"mail": {
"mail1": "X";
"mail2": "X";
},
},
{
"id": "2,",
"amount": "X",
},
}
],
"data": [
{
"order": {
"id": "3,",
"amount": "X",
},
}
],
I need to remove the first and last sub-arrays so I only get only one nest:
[1] {
"id": "[email protected],",
"mail1": "X",
"mail2": "X",
},
[2] {
"id": "2,",
"amount": "X",
},
[3] {
"id": "3,",
"amount": "X",
},
I don't know if this make sense. I'm sure this is not very difficult to do, but I only managed to make a foreach that creates an array with all values, but I lose all sub arrays.
How is this done? (at least removing the first array).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的数组结构仍然无效,所以我不能肯定地说,但应该这样做:
Your array structure is still invalid so I can't say for sure, but something along these lines should do:
试试这个:
希望有帮助
Try this:
Hope it helps