PHP implementation of two tables merged into a new table and arranged in an orderly way
The implementation method is as follows:
The code is as follows:
/**
La (3,5,8,11)
LB (2,6,8,9,11,15)
Merged into LC, arranged in order.
With PHP, you can't use a function like sort!!!
**/
Class Union {
var $lista = array ();
var $listb = array ();
var $LISTC = array ();
function Getlenght ($arr) {//Get table length
return count ($arr);
}
function GetElement ($arr, $n) {//Gets the nth element of a table, returns
return $e = $arr [$n]? $arr [$n]: ';
}
function Listinsert ($arr, $e) {//end of Table Insert element
$arr [] = $e;
return $arr;
}
}
$phpig = new Union ();
$lista = $phpig->lista = Array (3, 5, 8, 11);
$listb = $phpig->listb = Array (2, 6, 8, 9, 11, 15);
$LISTC = $phpig->listc;
$lena = $phpig->getlenght ($lista); Get table Size
$lenb = $phpig->getlenght ($LISTB);
$i = $j = 0;
while ($i < $lena && $j < $lenb) {
$ea = $phpig->getelement ($lista, $i);
$eb = $phpig->getelement ($LISTB, $j);
if ($ea <= $eb) {
$LISTC = $phpig->listinsert ($LISTC, $ea);
+ + $i;
} else {
$LISTC = $phpig->listinsert ($LISTC, $eb);
+ + $j;
}
}
while ($i < $lena) {
$ea = $phpig->getelement ($lista, $i);
$LISTC = $phpig->listinsert ($LISTC, $ea);
+ + $i;
}
while ($j < $lenb) {
$eb = $phpig->getelement ($LISTB, $j);
$LISTC = $phpig->listinsert ($LISTC, $eb);
+ + $j;
}
Print_r ($LISTC);
?>
http://www.bkjia.com/PHPjc/922887.html www.bkjia.com true http://www.bkjia.com/PHPjc/922887.html techarticle PHP Implementation of two tables merged into a new table and ordered the method of implementation of the following: The code is as follows:? PHP/** La (3,5,8,11) lb (2,6,8,9,11,15) merged into LC with ...