取消设置多维数组中的列

我有这个数组$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
    )
)

答案 1

不能用简单的命令完成,但可以使用循环:

foreach(array_keys($output) as $key) {
   unset($output[$key][1]);
}

答案 2

干净整洁:

$f = function(&$a,$k) { unset($a[1]); };
array_walk($arr, $f);

艺术

array_walk($arr, function (&$a, $k) {
  unset($a[1]); 
});

推荐