Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中更改多维数组的键_Php - Fatal编程技术网

在PHP中更改多维数组的键

在PHP中更改多维数组的键,php,Php,这是我的第一个数组 Array ( [0] => Array ( [0] => 1 [1] => Elite [2] => Air-Con Bus [3] => Monday ) [1] => Array ( [0] => 4 [1] => K

这是我的第一个数组

Array
(
   [0] => Array
        (
            [0] => 1
            [1] => Elite
            [2] => Air-Con Bus
            [3] => Monday
        )

    [1] => Array
        (
            [0] => 4
            [1] => KBZ
            [2] => Airplane
            [3] => Wednesday
        )
    [2] => Array
        (
            [0] => 5
            [1] => Yoma
            [2] => Cruise
            [3] => Tuesday
        )
)
我想将内部
数组[0]
连接到外部数组键。就像下面的数组:我能不能?请推荐我

Array(
     [1] => Array
        (
            [0] => 1
            [1] => Elite
            [2] => Air-Con Bus
            [3] => Monday
        )

    [4] => Array
        (
            [0] => 4
            [1] => KBZ
            [2] => Airplane
            [3] => Wednesday
        )

    [5] => Array
        (            
            [0] => 5
            [1] => Yoma
            [2] => Cruise
            [3] => Tuesday
        )
)
单向:

foreach ($array as $a){
$new[$a[0]]=$a;
}

对我可以那样做!非常感谢!:)我真的很好奇:为什么这个琐碎的解决方案不明显?它几乎来自您对问题的描述:使用元素[0]作为新数组的键。是的。我可以那样做!非常感谢!:)
foreach ($array as $a){
$new[$a[0]]=$a;
}