Wednesday, 24 September 2014

array_intersect_assoc in PHP

array_intersect_assoc() function returns a result array with the keys and values from the first input array, only if they are present in all of the other input arrays.

Syntax:   array_intersect_assoc(array1,array2,array3...)

Parameters Description:
array1 : Required. The first array is the array compared with all other input arrays
array2 : Required. An array to be compared with the first array
array3 : Optional. An array to be compared with the first array

Example:

<?php
$daysarr1 = array(0=>"Sunday",1=>"Monday",2=>"Tuesday");
$daysarr2 = array(3=>"Tuesday",1=>"Monday",5=>"Thursday");
$daysarr3 = array(6=>"Wednesday",1=>"Monday",8=>"Thursday");
print_r( array_intersect_assoc($daysarr1,$daysarr2) );
?>

O/P:


Array ( 
        [1] => Monday
     )

0 comments:

Post a Comment