Write a PHP function to set union of two arrays.
<?php function array_union($x, $y) { $aunion= array_merge( array_intersect($x, $y), array_diff($x, $y), array_diff($y, $x) ); return $aunion; } $a = array(1, 2, 3, 4); $b = array(2, 3, 4, 5, 6); print_r(array_union($a, $b)); ?>
Sample Output:
Array ( [0] => 2 [1] => 3 [2] => 4 [3] => 1 [4] => 5 [5] => 6 )
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:Array ( [0] => 2 [1] => 3 [2] => 4 [3] => 1 [4] => 5 [5] => 6 )need an explanation for this answer? contact us directly to get an explanation for this answer