Dutch PHP Conference 2025 - Call For Papers

array_uintersect_assoc

(PHP 5, PHP 7, PHP 8)

array_uintersect_assocComputes the intersection of arrays with additional index check, compares data by a callback function

Опис

array_uintersect_assoc(array $array, array ...$arrays, callable $value_compare_func): array

Computes the intersection of arrays with additional index check, compares data by a callback function.

Note that the keys are used in the comparison unlike in array_uintersect(). The data is compared by using a callback function.

Параметри

array

The first array.

arrays

Arrays to compare against.

value_compare_func

Порівняльна функція має повертати ціле число, котре менше, рівне або більше нуля, якщо перший параметр вважається відповідно меншим, рівним або більшим за другий.

callback(mixed $a, mixed $b): int
Застереження

Якщо функція порівняння повертає не цілі значення, такі як float, вони будуть приведені до типу int під час повернення з функції зворотнього виклику. Тож значення, схожі на 0.99 або 0.1 будуть приведені до цілого 0, отже члени порівняння вважатимуться однаковими.

Застереження

Сортувальна функція зворотнього виклику повинна опрацьовувати будь-яке значення з будь-якого масиву у будь-якій послідовності, не залежно від їхнього початкового порядку. Це тому, що кожен масив впорядковується перед порівнянням його з іншими масивами. Наприклад:

<?php
$arrayA
= ["string", 1];
$arrayB = [["value" => 1]];
// $item1 та $item2 можуть бути "string", 1 чи ["value" => 1]
$compareFunc = static function ($item1, $item2) {
$value1 = is_string($item1) ? strlen($item1) : (is_array($item1) ? $item1["value"] : $item1);
$value2 = is_string($item2) ? strlen($item2) : (is_array($item2) ? $item2["value"] : $item2);
return
$value1 <=> $value2;
};
?>

Значення, що повертаються

Returns an array containing all the values of array that are present in all the arguments.

Приклади

Приклад #1 array_uintersect_assoc() example

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

print_r(array_uintersect_assoc($array1, $array2, "strcasecmp"));
?>

Поданий вище приклад виведе:

Array
(
    [a] => green
)

Прогляньте також

  • array_uintersect() - Computes the intersection of arrays, compares data by a callback function
  • array_intersect_assoc() - Computes the intersection of arrays with additional index check
  • array_intersect_uassoc() - Computes the intersection of arrays with additional index check, compares indexes by a callback function
  • array_uintersect_uassoc() - Computes the intersection of arrays with additional index check, compares data and indexes by separate callback functions

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top