Home > Backend Development > PHP Tutorial > PHP simple implementation process of merging two tables into a new table

PHP simple implementation process of merging two tables into a new table

黄舟
Release: 2023-03-15 11:16:02
Original
1916 people have browsed it

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);
?>
Copy after login

Run the file, and the result will be as shown below:

PHP simple implementation process of merging two tables into a new table

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!

Related labels:
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