Q:

Write a PHP function to set union of two arrays

belongs to collection: PHP array programs with examples

0

Write a PHP function to set union of two arrays

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

PHP is a server scripting language, and It is a powerful tool for making interactive and dynamic Web-pages. I have used WampServer 2.2 for following excercise..

<?php
function array_union($x, $y)
   { 
      $aunion=  array_merge(
            array_intersect($x, $y),
            array_diff($x, $y),     
            array_diff($y, $x)      
        );
        return $aunion;
   }
$p = array(1, 2, 3, 4,5);
$r = array(2, 3, 4, 5, 6,7,8);
print_r(array_union($p, $r));
?>

Result:

Array ( [0] => 2 [1] => 3 [2] => 4 [3] => 5 [4] => 1 [5] => 6 [6] => 7 [7] => 8 )

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write a PHP script that displays 1 2 3 4 5 6 7 8 9... >>
<< Write a PHP script to sort an array in reverse ord...