★ wanayoo — archive 1999 http://www.php.net/manual/it/function.array-intersect.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to Arrays
Quick Reference
English version of this pageGerman version of this page is not availableJapanese version of this page
Italian version of this pageFrench version of this pageHungarian version of this page
Spanish version of this page is not availableDutch version of this pageBrazilian Portuguese version of this page
Korean version of this pageCzech version of this page
Arrays
* array
* array_count_values
* array_diff
* array_flip
* array_intersect
* array_keys
* array_merge
* array_merge_recursive
* array_multisort
* array_pad
* array_pop
* array_push
* array_rand
* array_reverse
* array_shift
* array_slice
* array_splice
* array_unique
* array_unshift
* array_values
* array_walk
* arsort
* asort
* compact
* count
* current
* each
* end
* extract
* in_array
* key
* krsort
* ksort
* list
* natsort
* natcasesort
* next
* pos
* prev
* range
* reset
* rsort
* shuffle
* sizeof
* sort
* uasort
* uksort
* usort

  Thanks to:
 Chek.com
 easyDNS
 VA Linux Systems

  Related sites:
Apache
MySQL
PostgreSQL
Zend Tech.

  Community:
LinuxFund.org
OSDN
Manual: array_intersect
View the source code for this pageSearch the site



Previous page
 array_flip
 Updated
Mon, 12 Feb 2001
array_keys 
Next page


array_intersect

(PHP 4 >= 4.0.1)

array_intersect -- Computes the intersection of arrays

Description

array array_intersect (array array1, array array2 [, array ...])

Array_intersect() returns an array containing all the values of array1 that are present in all the arguments. Note that keys are preserved.

Esempio 1. Array_intersect() example


$array1 = array ("a" => "green", "red", "blue");
$array2 = array ("b" => "green", "yellow", "red");
$result = array_intersect ($array1, $array2);
      

This makes $result have array ("a" => "green", "red");

See also array_diff().


User Contributed Notes: array_intersect


venaas@php.net
22-Oct-2000 06:06
Fixed now, will show up in 4.0.4


zeekamotay@hotmail.com
05-Dec-2000 10:38
There's no array_union() function, but you can do this:
array_unique(array_merge($array1,$array2))



xx@xx.com
19-Feb-2001 07:52
Here is the equivalent to array_intersect for PHP3 users :

function array_intersect($array1, $array2) {
if (sizeof($array1) > sizeof($array2)) {
$array3 = $array2;
$array2 = $array1;
$array1 = $array3;
}
$endarray = array (0 => 0);
$j = 0;
for ($i = 0; $i < sizeof($array1); $i++) {
if (in_array($array1[$i], $array2)){
$endarray[$j] = $array1 [$i];
$j++;
}
}
return ($endarray);
}



 About Notes


Previous page
 array_flip
 Updated
Mon, 12 Feb 2001
array_keys 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.