Home > Article > Backend Development > PHP simple implementation process of merging two tables into a new table
In our daily development work, we inevitably have to deal with databases and data tables. We usually encounter multi-table queries, joint table queries, and merging two tables to generate a new table, etc. Today we will give We will introduce a simple PHP method to merge two tables into a new table class, merge two tables into one table, and arrange them in an orderly manner, involving array traversal and sorting operation skills, which has certain practical value!
The first step is to download the simple PHP two tables we need to use for this course to merge into a new table class library: http://www.php.cn/xiazai/leiku/540
The second step, after the download is completed, find the php class file we need, unzip it to our local directory, and create a new php file!
The third step, after completion, we need to call this class in the new php file and instantiate the class:
<?php include_once "biao.php"; //引入类文件 $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); //取得表大小 $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); ?>
Run the file, and the result will be as shown below:
The above is the detailed content of PHP simple implementation process of merging two tables into a new table. For more information, please follow other related articles on the PHP Chinese website!