重新排列数组以进行代码优化

时间:2016-11-30 11:06:22

标签: php arrays

我有如下数组,

$array = Array
(
    [0] => Array
        (
            [machine_id] => DKAN0090
        )

    [1] => Array
        (
            [machine_id] => DKAN0170
        )

    [2] => Array
        (
            [machine_id] => DKAN0470
        )

    [3] => Array
        (
            [machine_id] => DKAN0370
        )

    [4] => Array
        (
            [machine_id] => DKAN0450
        )
....
....
....

   [4000] => Array
        (
            [machine_id] => DKAN0450
        )
);

但我希望这个数组如下,

$arterarray =Array
(
    [0] => DKAN0090
    [1] => DKAN0170
    [2] => DKAN0470
    [3] => DKAN0370
    [4] => DKAN0450
    ...
    ...
    ...
    [4000] => DKAN0789

); 

目前我使用下面的代码来获取最终数组,

$machine= array();
        $i = 0;
        foreach ($array as $key => $record) {            
            $machine[$i] = $record["machine_id"];          
            $i++;
        }

请建议我另一种获得此阵列排列结果的方法,这可以帮助我更快地获得结果?

0 个答案:

没有答案