Coding Villa

Arrays Intersection using array_intersect in PHP

Author : Tahreem Anwar

Share with Friends
Views : 423
Ratings : 0
Bookmarks : 0
Farourities : 0

Description


In this simple article you will learn about Arrays Intersection using array_intersect in PHP.


Advertisements


 

 

Purpose:

 

Array_intersect function takes two or more arrays and returns values that are same with first array.

 

Code:

 

1.    <?php

2.    $names1=array(0=>"Tahreem",1=>"Rizwan",2=>"Anwar");

3.    $names2=array(3=>"Tahreem",4=>"Rizwan",5=>"Misbah");

4.    print_r(array_intersect($names1,$names2));

5.    ?>

 

Output:

 

 

Array ( [0] => Tahreem [1] => Rizwan )

 

 

Explanation:

 

 

On line 2 and line 3 we have declared two arrays $names1, $names2 and initialize it. On line 4 we have passed both of the arrays to array_intersect function that compares both of the arrays for the same elements it prints the same elements of the array.

 



Article Tags
Share with Friends

Comments




Leave a Reply

Name (required)  
Mail (will not be published) (required)   
 
Enter This Code
Captcha
 

Advertisements

Article Categories

.NET


Databases


Mobile Development


Operating Systems


Web Development


Coding Villa on Facebook