array_diff and array_intersect

array_diff and array_intersect

array_diff()
This function is used to find the difference between two arrays. This function gets two arguments, both arguments should be an array.And it returns an array that will contain all the values of argument1 which are not in argument2.

For example
$arr1 = array(1,2,3,4,5);
$arr2 = array(0,3,4,5,6);

$temp = array_diff($arr1,$arr2);
print_r($temp);

Now $temp array will contain (1,2)

array_intersect
This function is used to find the common elements between two arrays.This function gets two arguments, both arguments should be an array.And it returns an array which will contain all the common elements in 2 arguments

For example
$arr1 = array(1,2,3,4,5);
$arr2 = array(0,3,4,5,6);

$temp1 = array_intersect($arr1,$arr2);
print_r($temp1);

Now $temp array will contain (3,4,5)

Leave a Reply


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.