将多维数组合并在一起以获得连续的键

时间:2013-11-12 11:36:47

标签: php arrays array-merge

我想将这两个数组合并在一起

Array
(
    [0] => Array
        (
            [type] => Person
            [relevance] => 0.700000
            [count] => 300
            [text] => Chris
        )
)
Array
(
    [0] => Array
        (
            [type] => Person
            [relevance] => 0.900000
            [count] => 400
            [text] => Chris
        )

    [1] => Array
        (
            [type] => Person
            [relevance] => 0.500000
            [count] => 200
            [text] => Tom
        )
)

所以我可能会有这样的结果

Array
(
    [0] => Array
        (
            [type] => Person
            [relevance] => 0.900000
            [count] => 400
            [text] => Chris
        )

    [1] => Array
        (
            [type] => Person
            [relevance] => 0.500000
            [count] => 200
            [text] => Tom
        )
    [2] => Array
        (
            [type] => Person
            [relevance] => 0.700000
            [count] => 300
            [text] => taye
        )
)

4 个答案:

答案 0 :(得分:1)

喜欢这个吗?

$array_final = array_merge($array_1, $array_2);

在官方文档网站上提及array_merge

答案 1 :(得分:0)

尝试使用foreach

// $array1 is your original array
foreach($array2 as $val) {
     array_push($array2,$val)
}

答案 2 :(得分:0)

使用array_merge docs并更快地检查文档:D

答案 3 :(得分:0)

您是否搜索过PHP Doc?

array_merge_recursive怎么办?