Note: Try not to manipulate the database in the loop.
1. Two one-dimensional arrays merged into one one-dimensional array
$a = Array (' Morning ', ' afternoon ', ' Night ');
$b = Array (' Breakfast ', ' lunch ', ' dinner ');
(1) The array element in $ A is the key name, and the array element in $b is a new array formed by the key value.
$c = Array_combine ($a, $b);
(2) The array element with the same key value as the $b in $ A is removed, preserving only the different array elements in $ A. That is, returns the difference set.
$c =array_diff ($a, $b);
(3) Remove the array elements in $ A with the same key name and key value as the $b, preserving only the different array elements in $ A, that is, returning the array of difference sets.
$a = Array (' Morning ', ' afternoon ', ' Night ');
$b = Array (' Breakfast ', ' Lunch ', ' Night ');
$c =array_diff_assoc ($a, $b);
Print_r ($c);
The output is:
(4) Remove the array element with the same key name as the $b in $ A, preserving only the different array elements in $ A, which means returning the array of difference sets.
$c =array_diff_key ($a, $b);
An empty array.
(5) The array elements in $ A that are identical to the key and key values in the $b are removed, preserving only the different array elements in $ A, that is, returning the difference array, and then using the user-defined function to compare the key names in the array of differences and reorder the groups.
(6) Remove the array element with the same key name as the $b in $ A, preserving only the different array elements in $ A, that is, returning the difference array, and then using the user-defined function to compare the key names in the array of differences and reorder the groups.
$a = Array (' Morning ', ' afternoon ', ' Night ', ' Today ', ' Yesterday ', ' tomorrow ');
$b = Array (' Breakfast ', ' Lunch ', ' Night ');
$c =array_diff_ukey ($a, $b, function ($a, $b) {
if ($a = = $b)
return 0;
return ($a > $b) -1:1;
});
Print_r ($c);
On the merging of PHP arrays