php 如何最简单的实现多个数组纵向合并?
edjason
12 years, 3 months ago
Answers
function array_merge_2()
{
$arrays = func_get_args();
$result = array();
// loop available array
foreach($arrays as $array) {
if(is_array($array)) {
// Loop values
foreach($array as $key => $value)
{
$result[$key][] = $value;
}
}
}
return $result;
}
//示例
$arr1 = array('a','b','c','d','e');
$arr2 = array(1,2,3,4);
$arr3 = array(array('a1','b1'),array('a2','b2'=>array('b2a1')));
print_r(array_merge_2($arr1, $arr2,$arr3));
星星魔力。
answered 12 years, 3 months ago