Home > Backend Development > PHP Tutorial > PHP merge sort array intersection_PHP tutorial

PHP merge sort array intersection_PHP tutorial

WBOY
Release: 2016-07-21 15:29:50
Original
820 people have browsed it

复制代码 代码如下:

$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]." ";//交集
$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++];
}
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/323353.htmlTechArticle复制代码 代码如下: $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($b, $n, $m, $j=0; while($i$n $j$m){ if...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template