PHP to implement two tables merged into a new table and orderly arrangement of the method

Source: Internet
Author: User

The implementation methods are as follows:

code is as follows: <?php


/**


La (3,5,8,11)


lb (2,6,8,9,11,15)


merged into LC, arranged in order.


is implemented in PHP, and 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) {//Get the nth element in the table, return


return $e = $arr [$n]? $arr [$n]: ';


    }


    


function Listinsert ($arr, $e) {//At the end of the 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);


?>
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.