downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

array_unique> <array_uintersect_uassoc
Last updated: Sun, 25 Nov 2007

view this page in

array_uintersect

(PHP 5)

array_uintersect — Sammensætter et array med ligheder mellem arrays, med tjek værdierne igennem en callback funktion

Beskrivelse

array array_uintersect ( array $array1 , array $array2 [, array $ ... ], callback $data_compare_func )

array_uintersect() returnerer et array som indeholder alle værdier fra array1 som findes i alle de andre argumenter. Sammenligningen af værdierne bliver gjort ved hjælp af en callback funktion.

Example#1 array_uintersect() eksempel

<?php
$array1 
= array("a" => "green""b" => "brown""c" => "blue""red");
$array2 = array("a" => "GREEN""B" => "brown""yellow""red");

print_r(array_uintersect($array1$array2"strcasecmp"));
?>

Ovenstående eksempel vil udskrive:

Array
(
    [a] => green
    [b] => brown
    [0] => red
)

Til sammenligning bliver den tilføjede callback funktion brugt. Den skal returnere et tal mindre, samme som, eller større end null, hvis det første argument skal bestemmes til at være enten mindre end, det samme som, eller større end det andet argument.

Se også array_intersect(), array_uintersect_assoc(), array_intersect_uassoc() og array_uintersect_uassoc().



add a note add a note User Contributed Notes
array_uintersect
Nate at RuggFamily dot com
02-Feb-2007 08:03
I want to stress that in the user function, you do need to return either a 1 or a -1 properly; you cannot simply return 0 if the results are equal and 1 if they are not. 

The following code is incorrect:

<?php
function myfunction($v1,$v2)
{
if (
$v1===$v2)
    {
    return
0;
    }
return
1;
}

$a1=array(1, 2, 4);
$a2=array(1, 3, 4);
print_r(array_uintersect($a1,$a2,"myfunction"));
?>

This code is correct:

<?php
function myfunction($v1,$v2)
{
if (
$v1===$v2)
    {
    return
0;
    }
if (
$v1 > $v2) return 1;
return -
1;
}
$a1=array(1, 2, 4);
$a2=array(1, 3, 4);
print_r(array_uintersect($a1,$a2,"myfunction"));
?>

array_unique> <array_uintersect_uassoc
Last updated: Sun, 25 Nov 2007
 
 
show source | credits | sitemap | contact | advertising | mirror sites