特别是+运算符,他的意思是,将右边的数组单元(去重复)追加到左边数组的后面。
<BR><?php <BR>echo "\r\n第一种情况\n"; <BR>$a=array(1,2,3,4,5,6); <BR>$b=array(7,8,9); <BR>$c=array_merge ($a,$b); <BR>print_r($c); <BR>$c=$a+$b; <BR>print_r($c); <BR>$c=$b+$a; <BR>print_r($c); <BR>echo "\r\n第二种情况\n"; <BR>$a=array('a','b','c','d','e','f'); <BR>$b=array('a','x','y'); <BR>$c=array_merge ($a,$b); <BR>print_r($c); <BR>$c=$a+$b; <BR>print_r($c); <BR>$c=$b+$a; <BR>print_r($c); <BR>echo "\r\n第三种情况\n"; <BR>$a=array( <BR>1=>'a', <BR>2=>'b', <BR>3=>'c', <BR>4=>'d', <BR>5=>'e', <BR>6=>'f'); <BR>$b=array( <BR>1=>'a', <BR>7=>'x', <BR>8=>'y'); <BR>$c=array_merge ($a,$b); <BR>print_r($c); <BR>$c=$a+$b; <BR>print_r($c); <BR>$c=$b+$a; <BR>print_r($c); <BR>?> <BR>
结果如下:
<BR>第一种情况 <BR>Array <BR>( <BR>[0] => 1 <BR>[1] => 2 <BR>[2] => 3 <BR>[3] => 4 <BR>[4] => 5 <BR>[5] => 6 <BR>[6] => 7 <BR>[7] => 8 <BR>[8] => 9 <BR>) <BR>Array <BR>( <BR>[0] => 1 <BR>[1] => 2 <BR>[2] => 3 <BR>[3] => 4 <BR>[4] => 5 <BR>[5] => <strong style="color:transparent">本&文来源gao@daima#com搞(%代@#码网@</strong><textarea>搞gaodaima代码</textarea>6 <BR>) <BR>Array <BR>( <BR>[0] => 7 <BR>[1] => 8 <BR>[2] => 9 <BR>[3] => 4 <BR>[4] => 5 <BR>[5] => 6 <BR>) <BR>第二种情况 <BR>Array <BR>( <BR>[0] => a <BR>[1] => b <BR>[2] => c <BR>[3] => d <BR>[4] => e <BR>[5] => f <BR>[6] => a <BR>[7] => x <BR>[8] => y <BR>) <BR>Array <BR>( <BR>[0] => a <BR>[1] => b <BR>[2] => c <BR>[3] => d <BR>[4] => e <BR>[5] => f <BR>) <BR>Array <BR>( <BR>[0] => a <BR>[1] => x <BR>[2] => y <BR>[3] => d <BR>[4] => e <BR>[5] => f <BR>) <BR>第三种情况 <BR>Array <BR>( <BR>[0] => a <BR>[1] => b <BR>[2] => c <BR>[3] => d <BR>[4] => e <BR>[5] => f <BR>[6] => a <BR>[7] => x <BR>[8] => y <BR>) <BR>Array <BR>( <BR>[1] => a <BR>[2] => b <BR>[3] => c <BR>[4] => d <BR>[5] => e <BR>[6] => f <BR>[7] => x <BR>[8] => y <BR>) <BR>Array <BR>( <BR>[1] => a <BR>[7] => x <BR>[8] => y <BR>[2] => b <BR>[3] => c <BR>[4] => d <BR>[5] => e <BR>[6] => f <BR>) <BR>