Write a PHP function to set union of two arrays

Introduction

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

Write a PHP function to set union of two arrays
Write a PHP function to set union of two arrays

Leave a Comment

x