Home >Backend Development >PHP Tutorial >array_merge合并问题

array_merge合并问题

WBOY
WBOYOriginal
2016-06-23 14:17:041127browse

merge 数组合并

假设$a    $b   $c 三个数组,a和b有值,如果c没有任何数据,array_merge( $a , $b , $c )后返回的是一个null值。

现在想c没数据的时候,array_merge( $a , $b , $c )也能返回a和b合并后的数据,请问有什么办法解决?

回复讨论(解决方案)

$a = array(1,2,3,4);$b = array(5,6,7,8);$c = array();$rest = array_merge($a,$b,$c);print_r($rest);

Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 ) 


没问题啊。

$a = array(1,2,3,4);$b = array(5,6,7,8);$c = array();$rest = array_merge($a,$b,$c);print_r($rest);

Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 ) 


没问题啊。

恩哼?不对劲啊,在公司明明不行的,明天上班回去看看代码先

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn