dongtuo2373 2016-03-06 09:48
浏览 56
已采纳

如何在PHP中将数组值推送到另一个数组?

I'm working with PHP 5.6 and I want to push values from an array in the end of another array so I tried the array_push function but It pushed the whole array like this:

Array
(
    [0] => Array
        (
            [0] => a
            [1] => b
            [2] => c
        )

    [1] => Array
       (
           [0] => d
           [1] => e
           [2] => f
       )
)

What I'm looking for is this :

 Array
 (
    [0] => Array
        (
            [0] => a
            [1] => b
            [2] => c
            [3] => d
            [4] => e
            [5] => f
       )

Is there any simpler way than looping over the array and adding values one by one :)

  • 写回答

2条回答 默认 最新

  • douzai3399 2016-03-06 09:53
    关注
    $r = array
    (
        array("a","b","c"),
        array("d","e","f")
    );
    $r1[] = call_user_func_array('array_merge', $r);
    print_r($r1);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?