取消设置多维数组中的行
我有这个数组 $output ,看起来像这样:
Array(
[0] => Array(
[0] => 1a
[1] => 1b
[2] => 1c
)
[1] => Array(
[0] => 2a
[1] => 2b
[2] => 2c
)
[2] => Array(
[0] => 3a
[1] => 3b
[2] => 3c
)
[3] => Array(
[0] => 4a
[1] => 4b
[2] => 4c
)
)
等等...
当我想删除第二个元素时,我只需使用:
$output = unset($output[1]);
得到以下内容:
Array(
[0] => Array(
[0] => 1a
[1] => 1b
[2] => 1c
)
[1] => Array(
[0] => 3a
[1] => 3b
[2] => 3c
)
[2] => Array(
[0] => 4a
[1] => 4b
[2] => 4c
)
)
我的问题是如何删除数组中每个元素的每个第二个元素( [0][1], [1][1], [2][1], [3][1] ,...) 得到以下结果:
Array(
[0] => Array(
[0] => 1a
[1] => 1c
)
[1] => Array(
[0] => 2a
[1] => 2c
)
[2] => Array(
[0] => 3a
[1] => 3c
)
[3] => Array(
[0] => 4a
[1] => 4c
)
)
I have this array $output which looks like this:
Array(
[0] => Array(
[0] => 1a
[1] => 1b
[2] => 1c
)
[1] => Array(
[0] => 2a
[1] => 2b
[2] => 2c
)
[2] => Array(
[0] => 3a
[1] => 3b
[2] => 3c
)
[3] => Array(
[0] => 4a
[1] => 4b
[2] => 4c
)
)
and so on...
When I want to remove the second element I just use:
$output = unset($output[1]);
to get the following:
Array(
[0] => Array(
[0] => 1a
[1] => 1b
[2] => 1c
)
[1] => Array(
[0] => 3a
[1] => 3b
[2] => 3c
)
[2] => Array(
[0] => 4a
[1] => 4b
[2] => 4c
)
)
My question is how to remove every second element of every element in the array ([0][1], [1][1], [2][1], [3][1] ,...) to get the following:
Array(
[0] => Array(
[0] => 1a
[1] => 1c
)
[1] => Array(
[0] => 2a
[1] => 2c
)
[2] => Array(
[0] => 3a
[1] => 3c
)
[3] => Array(
[0] => 4a
[1] => 4c
)
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
无法通过简单的命令完成,但可以使用循环:
Can't be done with a simple command, but you can use a loop:
干净整洁:
或:
Clean and neat:
Or:
您可以迭代数组,并在每个子数组中
unset()
您想要的内容:You can iterate over the array, and
unset()
what you want in each sub-array:您可以使用
array_map
和array_splice
的组合:unset
的问题是它会使索引保持原样:而 splice 会更新索引:
You'd use a combination of
array_map
andarray_splice
:The problem with
unset
is that it will leave the indexes as they were:While splice will update the indexes:
我用这个:
I use this: