PHP method to implement association table based on array function

墨辰丷
Release: 2023-03-27 06:12:02
Original
1163 people have browsed it

This article mainly introduces the editing operations of association tables in PHP based on array functions, involving the related usage skills of PHP array comparison functions array_intersect and array_diff. Friends in need can refer to the following

The details are as follows:

$arr1 = array(1, 2, 4, 5, 6, 9); // 学校应用关联表中一开始的数据
$arr2 = array(3, 4, 5, 7, 8);  // 前台更新的数据
/*
两个数组相同的元素,提取不变的元素
Array
(
  [2] => 4
  [3] => 5
)
*/
$arr3 = array_intersect($arr1, $arr2);
print_r($arr3);
/*
两个数组不同的元素,需要删除的
Array
(
  [0] => 1
  [1] => 2
  [4] => 6
  [5] => 9
)
*/
$arr4 = array_diff($arr1, $arr3);
print_r($arr4);
/*
两个数组不同的元素,需要添加的
Array
(
  [0] => 3
  [3] => 7
  [4] => 8
)
*/
$arr5 = array_diff($arr2, $arr3);
print_r($arr5);
Copy after login

Related recommendations:

php array function implementationEditing of association table

#Cakephp query Summary of methods for associated tables

mysql How to obtain the value of the corresponding field in the associated table when the main table is output?

##

The above is the detailed content of PHP method to implement association table based on array function. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!