用数字键替换命名键

时间:2014-04-08 23:25:10

标签: php multidimensional-array

在多维数组中用数字键替换命名键的最有效和最简洁的方法是什么?

我的阵列:

Array 
(
    [0] => Array 
        (
            [Property] => Brock
            [Meint. Type] => grounds
            [Maint. Task] => plow snow
            [Status] => cancelled
            [Started] =>
            [Completed] =>
            [Comments] =>
        )

    [1] => Array 
        (
            [Property] => Brock
            [Meint. Type] => grounds
            [Maint. Task] => plow snow
            [Status] => pending
            [Started] => 2010-01-16
            [Completed] =>
            [Comments] =>
        )

    [2] => Array
        ( 
            [Property] => Brock
            [Mains. Type] => grounds
            [Maint. Task] => plow snow
            [Status] => complete
            [Started] => 2010-01-16
            [Completed] => 2010-01-16
            [Comments] =>
        )

    [3] => Array 
        (
            [Property] => Brock
            [Mains. Type] => grounds
            [Maint. Task] => plow snow
            [Status] => in progress
            [Started] => 2014-01-16
            [Completed] => 2014-01-16
            [Comments] =>
        )

    [4] => Array

目标是将[Property]替换为[0],[Maint。键入] [1](它应该有方括号,它们会被自动删除),[Maint。任务] [2],[状态],[3]等,用于每个子阵列。

1 个答案:

答案 0 :(得分:1)

$modified_array = array_map('array_values', $arr);

说明:array_map()array_values()函数应用于$arr数组中的每个元素。