如何在php中使用单个变量完成此操作?



好的,我有一个包含多个数组的$unique_answer_title。下面是我使用var_dump($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" } array(18) { [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" [12]=> string(9) "Immediate" [13]=> string(2) "No" [14]=> string(15) "Send literature" [15]=> string(77) "Sign me up for more info on the Biomek 4000<sup>&#134;</sup>." [16]=> string(88) "Biomek<sup><em>&#135;&#135;</em></sup> Assay Workstation" [17]=> string(72) "SPRIworks Library Construction <sup>&#94;&#94;</sup>" } array(22) { [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" [12]=> string(9) "Immediate" [13]=> string(2) "No" [14]=> string(15) "Send literature" [15]=> string(77) "Sign me up for more info on the Biomek 4000<sup>&#134;</sup>." [16]=> string(88) "Biomek<sup><em>&#135;&#135;</em></sup> Assay Workstation" [17]=> string(72) "SPRIworks Library Construction <sup>&#94;&#94;</sup>" [18]=> string(9) "Immediate" [19]=> string(2) "No" [20]=> string(30) "Have a representative visit me" [21]=> string(77) "Sign me up for more info on the Biomek 4000<sup>&#134;</sup>." } array(26) { [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" [12]=> string(9) "Immediate" [13]=> string(2) "No" [14]=> string(15) "Send literature" [15]=> string(77) "Sign me up for more info on the Biomek 4000<sup>&#134;</sup>." [16]=> string(88) "Biomek<sup><em>&#135;&#135;</em></sup> Assay Workstation" [17]=> string(72) "SPRIworks Library Construction <sup>&#94;&#94;</sup>" [18]=> string(9) "Immediate" [19]=> string(2) "No" [20]=> string(30) "Have a representative visit me" [21]=> string(77) "Sign me up for more info on the Biomek 4000<sup>&#134;</sup>." [22]=> string(9) "Immediate" [23]=> string(2) "No" [24]=> string(5) "Other" [25]=> string(88) "Biomek<sup><em>&#135;&#135;</em></sup> Assay Workstation" }

如何将这些数组中的所有元素组合成一个数字数组?

array_merge($unique_answer_title)似乎不起作用…变量$unique_answer_title本身不是一个数组,它是一组多个数组。我怎样才能把这些单独数组的元素组合成一个大数组呢?

您需要在foreach循环中合并单个数组。

$mergedArray = array();
foreach($unique_answer_title as $single){
  $mergedArray = array_merge($mergedArray, $single);
}

相关内容

  • 没有找到相关文章

最新更新