Using array_merge() and the + operator with associative arrays as well : array_merge « Data Structure « PHP






Using array_merge() and the + operator with associative arrays as well

 
<?php 
    function array_display($array, $pre=FALSE) { 
        $tag = $pre ? 'pre' : 'p'; 
        printf("<%s>%s</%s>\n", $tag, var_export($array, TRUE), $tag); 
    } 

    $dogs1 = array('A' => 'C', 'B' => 'C', 'D' => 'C'); 

    $dogs2 = array('a' => 'a', 'b' => 'b'); 
   
   array_display(array_merge($dogs1, $dogs2), TRUE); 
   array_display($dogs1 + $dogs2, TRUE); 
?>
  
  








Related examples in the same category

1.Appending One Array to Another
2.array_merge
3.array_merge( ) function combines two or more arrays by renumbering numerical indexes and overwriting string indexes
4.array_merge( ) retains array keys when possible.
5.array_merge() and + operator
6.array_merge() example
7.array_merge() function merges 1 to N arrays together
8.obtaining the union of two arrays