Difference between two arraysWe can find out difference of two arrays by using array_diff function. This function takes two arrays as input and then returns the result array. Syntax of this function is here.
For example let us use one array a1 and store text entered by user in a web form after converting the text string to an array. Now to prevent spammers posting URL or posting of some bad words we will develop another array a2 where all negative words we will store. These words we don't want to be present in the first ( a1) array.
Here is the example of how the array_diff works
The output of above code will be
0 -> first
2 -> third
4 -> fifth