In our daily development work, we have to deal with the database and data tables, we usually encounter multi-table query, table query, and two tables merge and then produce a new table and so on, today we will introduce a simple PHP simple two tables merged into a new table class, the 2 tables into 1 tables, and orderly arrangement of methods, involving the array of traversal and sequencing operation skills, has a certain practical value!
The first step is to first download the PHP simple two tables we need to use in this lesson to merge into the new Table class library: http://www.php.cn/xiazai/leiku/540
The second step, after the download, find the PHP class files we need, unzip to our local directory, create a new PHP file!
After the third step, we will call this class in the new PHP file, and instantiate the class:
<?phpinclude_once "biao.php"; Introduce class file $phpig = new Union (); Instantiate class $lista = $phpig->lista = Array (3, 5, 8, one); $listb = $phpig->listb = Array (2, 6, 8, 9, one, and up); $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);? >
Run the file and get the results as shown: