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);
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!