数组分离并存储到一个数组中

时间:2017-04-10 10:58:27

标签: php

Array
(
    [0] => Array
        (
            [0] => 13.75
            [1] => 26
            [2] => 18
            [3] => 38
        )

    [1] => Array
        (
            [0] => 7.15
            [1] => 26
            [2] => 18
            [3] => 38
        )

)

Array
(
    [0] => Array
        (
            [0] => 13.75
            [1] => 26
            [2] => 18
            [3] => 38
        )

    [1] => Array
        (
            [0] => 8.25
            [1] => 26
            [2] => 18
            [3] => 38
        )

我有两个包含多个元素的数组,我需要在一个数组中使用逗号分隔所有值,如下所示: 阵列

(
    [0] => Array
        (
            [0] => 13.75,
            [1] => 26,
            [2] => 18,
            [3] => 38
        ),

    [1] => Array
        (
            [0] => 7.15,
            [1] => 26,
            [2] => 18,
            [3] => 38
        ),



    [2] => Array
        (
            [0] => 13.75,
            [1] => 26,
            [2] => 18,
            [3] => 38
        )

    [3] => Array
        (
            [0] => 8.25,
            [1] => 26,
            [2] => 18,
            [3] => 38
        )

)

2 个答案:

答案 0 :(得分:1)

您可以使用array_merge函数合并两个数组。

见下面的代码

$arr1 = array(array(13.75,26,18,38),array(7.15,26,18,38)); // <- your first array
$arr2 = array(array(13.75,26,18,38),array(8.25,26,18,38)); // <- your second array

$myarr = array_merge($arr1,$arr2);
echo "<pre>";
print_r($myarr);

答案 1 :(得分:0)

@vivek manavadariya只需使用foreach(),如下所示:

    <?php
        $arr1 = array(
                    array(
                            0 => 13.75,
                            1 => 26,
                            2 => 18,
                            3 => 38
                        ),

                    array(
                            0 => 7.15,
                            1 => 26,
                            2 => 18,
                            3 => 38
                        )

            );

    $arr2 = array(
                array(
                        0 => 13.75,
                        1 => 26,
                        2 => 18,
                        3 => 38
                    ),
                array(
                        0 => 8.25,
                        1 => 26,
                        2 => 18,
                        3 => 38
                    )
            );
    $finalArr = array();
    foreach ($arr1 as $value) {
        $finalArr[] = $value;
    }
    foreach ($arr2 as $value) {
        $finalArr[] = $value;
    }


    // or with array_merge()


   $finalArr = array_merge($arr1, $arr2);


    echo "<pre>";
    print_r($finalArr);