如何合并存储在变量中的多个单独数组,这些数组本身不包含在数组中?变量$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>‡‡</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>‡‡</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>‡‡</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>‡‡</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>‡‡</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>‡‡</em></sup> FX<sup>P</sup> Workstation"
}
答案 0 :(得分:1)
您在代码中对问题的简短回答是:
$merged = call_user_func_array('array_merge', $unique_answer_title);
这会将您拥有的一个数组转换为多个参数array_merge()
,接受任意数量的参数。
之前(2010年9月)概述于:
如果你然后抱怨双值,那么这已经处理过了:
答案 1 :(得分:0)
你必须遍历每一个并合并它们:
$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);
真的,您要问的是如何展平多维数组,以下内容也可能会有所帮助:How to "flatten" a multi-dimensional array into a simple one in PHP?