如何更改下面多维数组的索引?
如何将此波纹管数组更改
Array
(
[0] => Array
(
[0] => Array
(
[0] => 35.2
)
[1] => Array
(
[0] => 49.5
)
)
[1] => Array
(
[0] => Array
(
[0] => 44
)
[1] => Array
(
[0] => 38.5
)
)
)
为
Array
(
[0] => Array
(
[0] => 35.2
[1] =>49.5
)
[1] => Array
(
[0] => 44
[1] => 38.5
)
)
How to change this bellow array
Array
(
[0] => Array
(
[0] => Array
(
[0] => 35.2
)
[1] => Array
(
[0] => 49.5
)
)
[1] => Array
(
[0] => Array
(
[0] => 44
)
[1] => Array
(
[0] => 38.5
)
)
)
into
Array
(
[0] => Array
(
[0] => 35.2
[1] =>49.5
)
[1] => Array
(
[0] => 44
[1] => 38.5
)
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最简单的方法是简单的嵌套 foreach:
Sheepy 建议使用 array_merge 和下面的 call_user_func_array 。这是个好主意,我给了+1。 (我鼓励其他人也这样做)。为了看看哪个更好,我决定对两种解决方案运行基准测试:
结果:
然后我颠倒了测试顺序:
这是基准测试代码:
The easy, easy way is a simple nested foreach:
Sheepy proposed use of array_merge with call_user_func_array below. That is a good idea and I gave it a +1. (I encourage others to do the same). To see which was better, I decided to run a benchmark on both solutions:
The results:
I then reversed test order:
Here's the benchmark code:
这是一个较短的版本。但实际上它仍然是一个嵌套循环。
Here is a shorter version. It is still a nested loop in reality, though.