Using Array_Merge() And The + Operator With Associative Arrays As Well

<?phpphp
    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);
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.