The built-in array_diff() function is used to compare array1 against one or more other arrays that is passed to it and then returns the values in array1 that are not present in any of the other arrays.
array array_diff ( array $array1, array $array2 [, array $array3 ...] );
|Sr.No||Parameter & Description|
This is the first array which will be compared with other arrays passed to the function.
This is an array to be compared with the first array
This is the second array to be compared with the first array
More Arrays (Optional)
You can pass more number of arrays you want to compare with the first input array.
<?php $array1 = array("orange", "banana", "apple"); $array2 = array("orange", "mango", "apple"); print_r(array_diff($array1, $array2)); ?>
Array (  => banana )
<?php $array1 = array("a" => "green", "red", "blue", "red"); $array2 = array("b" => "green", "yellow", "red"); print_r(array_diff($array1, $array2)); ?>
Array (  => blue )
Feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.