将多维数组转换为一维数组PHP

时间:2014-08-04 15:17:31

标签: php arrays multidimensional-array

如何转换此数组格式:

Array ( [0] => Array ( [quantity] => 200.00000000 ) 
[1] => Array ( [quantity] => 200.00000000 ) [2] => Array ( [quantity] => 200.00000000 )
[3] => Array ( [quantity] => 200.00000000 ) [4] => Array ( [quantity] => 200.00000000 ) 
[5] => Array ( [quantity] => 200.00000000 ) [6] => Array ( [quantity] => 200.00000000 ) 
[7] => Array ( [quantity] => 200.00000000 ) ) 

到这种形式:

 Array ( [0] => 200 [1] => 200 [2] => 200 [3] => 200 [4] => 200 [6] => 200 [7] => 200 ) 
PHP中的

。提前谢谢。

1 个答案:

答案 0 :(得分:0)

此功能可以帮助您

function convert($array)
{
    $result = [];
    foreach ($array as $key => $value) 
        $result[] = $value['quantity'];
    return $result;
}

$array = convert($array);