Bladephp: Now with 7+ codeigniter, php, and laravel project 7+ php project From $18/Year From Rs. 1000/Year

PHP array_intersect() Function

by
Category:php
php php array function
PHP array_intersect() Function

The array_intersect() function compares the values of two (or more) arrays, and returns the matches.

This function compares the values of two or more arrays, and return an array that contains the entries from array1 that are present in array2, array3, etc.

Parameter Description
array1 Required. The array to compare from
array2 Required. An array to compare against
array3,... Optional. More arrays to compare against

Syntax

 array_intersect(array1,array2,array3...);

Example

$array1=array("a"=>"Prince","b"=>"James","c"=>"Samuel","d"=>"Cooper");
$array2=array("e"=>"Prince","f"=>"James","g"=>"Samuel");
$result=array_intersect($array1,$array2);
print_r($result);

Output

Array ( [a] => Prince [b] => James [c] => Samuel ) 

0 Comments


Html code work in comment box


Related Post