obtaining the union of two arrays : array_merge « Data Structure « PHP






obtaining the union of two arrays

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

    $arr5 = array(1 => 'x', 2 => 'y', 3 => 'z'); 
    $arr1 = array(1 => 'x', 2 => 'y', 3 => 'z'); 
    
    array_display(array_merge($arr1, $arr5), TRUE); 
    array_display($arr1 + $arr5, TRUE); 
?>
  
  








Related examples in the same category

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