Copy the code The code is as follows:
$a=array('1','2','3','4','22');
$b=array('1',' 3','4','11','22','23');
f($a, $b, 5, 6, $t);
print_r($t);
function f(&$ a, &$b, $n, $m, &$t){
$i=0;$j=0;
while($i<$n && $j<$m){
if($a[ $i]==$b[$j]){
echo $a[$i]." ";//Intersection
$t[]=$a[$i++];
$t[]=$b[ $j++];
}elseif($a[$i]>$b[$j]){
$t[]=$b[$j++];
}else{
$t[]=$a[ $i++];
}
}
while($i<$n){
$t[]=$a[$i++];
}
while($j<$m){
$t[]=$ b[$j++];
}
}
The above introduces merge sort, php merge sort, and array intersection, including the content of merge sort. I hope it will be helpful to friends who are interested in PHP tutorials.