如何合并未包含在数组中的多个独立数组


How can I merge multiple separate arrays that are not included in an array?

如何合并存储在变量中的多个独立数组,这些变量不包含在数组本身中?变量$unique_answer_title包含这些单独的数组,然而,我试图将它们的所有元素组合成一个大的数值数组。当我用array_merge($unique_answer_title)时,没有返回任何东西。下面是变量..

中包含的数据
array(4) {
        [0]=> string(9) "Immediate" 
        [1]=> string(3) "Yes" 
        [2]=> string(29) "Have a representative call me" 
        [3]=> string(109) "Biomek<sup><em>&#135;&#135;</em></sup> FX<sup>P</sup> Workstation" 
        } 
    array(8) { 
        [0]=> string(9) "Immediate" 
        [1]=> string(3) "Yes" 
        [2]=> string(29) "Have a representative call me" 
        [3]=> string(109) "Biomek<sup><em>&#135;&#135;</em></sup> FX<sup>P</sup> Workstation" 
        [4]=> string(9) "Immediate" 
        [5]=> string(2) "No" 
        [6]=> string(29) "Have a representative call me" 
        [7]=> string(111) "Biomek<sup><em>&#135;&#135;</em></sup> NX<sup>P</sup> Workstation " 
        } 
    array(12) { 
        [0]=> string(9) "Immediate" 
        [1]=> string(3) "Yes" 
        [2]=> string(29) "Have a representative call me" 
        [3]=> string(109) "Biomek<sup><em>&#135;&#135;</em></sup> FX<sup>P</sup> Workstation" 
        [4]=> string(9) "Immediate" 
        [5]=> string(2) "No" 
        [6]=> string(29) "Have a representative call me" 
        [7]=> string(111) "Biomek<sup><em>&#135;&#135;</em></sup> NX<sup>P</sup> Workstation " 
        [8]=> string(20) "Greater than 3 years" 
        [9]=> string(3) "Yes" 
        [10]=> string(42) "Have a representative contact me via email" 
        [11]=> string(109) "Biomek<sup><em>&#135;&#135;</em></sup> FX<sup>P</sup> Workstation" 
        }

你的问题在代码中的简短答案是:

$merged = call_user_func_array('array_merge', $unique_answer_title);

这是把一个数组变成多个参数的array_merge(),它接受任何数量的参数。

此前(2010年9月)已在:

中概述:
    一个更好的php array_merge

如果你抱怨双精度值,这个问题也已经解决了:

    PHP合并数组并删除双值

你必须遍历它们并合并它们:

$test = array(
 array(
  "Immediate",
  "Yes"
 ),
 array(
  'Test 2',
  'test 3'
 ),
 array(
  'test4',
  'test5'
 )
);
$new_array = array();
foreach($test as $array) $new_array = array_merge($new_array, $array);
var_dump($new_array);

真的,你问的是如何扁平化一个多维数组,下面的内容可能也会有所帮助:如何在PHP中"扁平化"一个多维数组?