There are three key functions that handle the comparison of two arrays to create a new array, and they work in much the same way - they take a minimum of two arrays as parameters (we will call them $arr1 and $arr2), and return an array for a result.
The difference is that array_diff() returns a new array containing all the values of $arr1 that do not exist in $arr2, array_intersect() returns a new array containing all the values of $arr1 that do exist in $arr2, and array_merge() just combines the two arrays. These three functions work well as a team, and allow you to construct combined arrays out of individual arrays.
Here is an example with these three functions in action:
Array_intersect(), if you recall, returns an array listing all values in array parameter one that are also in array parameter two, so this call in our example will put just one element, cheese, into $inttoppings. The call to array_diff() will place into $difftoppings all the values from $toppings1 that aren't in $toppings2, namely pepperoni, anchovies, and tomatoes.
Finally we have a call to array_merge(), which results in seven elements being placed into $bothtoppings: pepperoni, cheese, anchovies, tomatoes, peppers, ham, and cheese. As you can see, "cheese" is in there twice, so what you really need now is a way to strip out duplicate values.
Author's Note: The + operator in PHP is overloaded so that you can use it to merge arrays, eg $array3 = $array1 + $array2, but will ignore any key clashes, and so is quite confusing to use unless you have unique keys.