1. The array_diff() function is used to compare the values of two (or more) arrays and return the difference.
grammar
array_diff(array1,array2,array3...);
2. array_diff() compares the values of two (or more) arrays (value in key=>value) and returns a difference array; the difference array includes all the values in the compared array (array1) , but a value that is not in any other parameter array (array2 or array3, etc.).
Example
<?php header("Content-type:text/html;charset=utf-8"); $a=array(1,2,3); $b=array(2,3,4); //Get an array consisting of elements that exist in $a but not in $b $c1=array_diff($a,$b); //Get an array consisting of elements that exist in $b but not in $a $c2=array_diff($b,$a); //Two arrays after removing the same elements echo 'Two arrays after removing the same elements:'.' '; var_dump($c1); var_dump($c2); ?>
The above is how PHP uses array_diff to remove elements. I hope it will be helpful to everyone. More PHP learning guide: PHP array