php +与array_merge的区别

  1. $a = array('a', 'b');
    $b = array('c', 'b');
    $c = $a + $b;
    print_r($c);
    print_r(array_merge($a, $b));

  2. $a = array(0 => 'a', 1 => 'b');
    $b = array(0 => 'c', 1 => 'b');
    $c = $a + $b;
    print_r($c);
    print_r(array_merge($a, $b));

  3. $a = array('a', 'b');
    $b = array('0' => 'c', 1 => 'b');
    $c = $a + $b;
    print_r($c);
    print_r(array_merge($a, $b));

  4. $a = array(0 => 'a', 1 => 'b');
    $b = array('0' => 'c', '2' => 'b');
    $c = $a + $b;
    print_r($c);
    print_r(array_merge($a, $b));

  1. Array
    (
    	[0] => a
    	[1] => b
    )
    Array
    (
    	[0] => a
    	[1] => b
    	[2] => c
    	[3] => b
    )
    		
  2. Array
    (
    	[0] => a
    	[1] => b
    )
    Array
    (
    	[0] => a
    	[1] => b
    	[2] => c
    	[3] => b
    )
    		
  3. Array
    (
    	[0] => a
    	[1] => b
    )
    Array
    (
    	[0] => a
    	[1] => b
    	[2] => c
    	[3] => b
    )
    		
  4. Array
    (
    	[0] => a
    	[1] => b
    	[2] => b
    )
    Array
    (
    	[0] => a
    	[1] => b
    	[2] => c
    	[3] => b
    )
    		

结论:+键值合并,merge值累加

posted @ 2012-09-17 14:44  snadn  阅读(152)  评论(0编辑  收藏  举报