php数组格式化(将数组转换为另一个数组)

时间:2014-12-03 05:27:56

标签: php arrays formatting

我在php中有一个数组,如下所示

Array
(
    [0] => Array
        (
            [0] => 0
            [1] => 4
        )

    [1] => Array
        (
            [0] => 5
            [1] => 0
        )

    [2] => Array
        (
            [0] => 0
            [1] => 8
        )

     [3] => Array
        (
            [0] => 10
            [1] => 27
        )

)

如何将其转换为以下格式。

array(0,4,5,0,0,8,10,27);

2 个答案:

答案 0 :(得分:1)

检查

foreach($mainarray as $s){
    foreach ($s as $v){
        $str .=$v.','; 
    }
}
echo $str;

答案 1 :(得分:1)

这样可以正常工作:

$array = array(array(1, 4), array(5, 0), array(0, 8), array(10, 27));

$result = array();

foreach ($array as $val)
{
  $result = array_merge($result, $val);
}

print_r($result);