array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'uk', ), 'this' => array ( 0 => 'function.array-diff-assoc.php', 1 => 'array_diff_assoc', 2 => 'Computes the difference of arrays with additional index check', ), 'up' => array ( 0 => 'ref.array.php', 1 => 'Функції для роботи з масивами', ), 'prev' => array ( 0 => 'function.array-diff.php', 1 => 'array_diff', ), 'next' => array ( 0 => 'function.array-diff-key.php', 1 => 'array_diff_key', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/array/functions/array-diff-assoc.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?>

array_diff_assoc

(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)

array_diff_assocComputes the difference of arrays with additional index check

Опис

array_diff_assoc(array $array, array ...$arrays): array

Compares array against arrays and returns the difference. Unlike array_diff() the array keys are also used in the comparison.

Параметри

array

The array to compare from

arrays

Arrays to compare against

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

Returns an array containing all the values from array that are not present in any of the other arrays.

Журнал змін

Версія Опис
8.0.0 Тепер ця функція може викликатись лише з одним параметром. Раніше потрібні були щонайменше два.

Приклади

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

In this example the "a" => "green" pair is present in both arrays and thus it is not in the output from the function. Unlike this, the pair 0 => "red" is in the output because the key of "red" is automatically assigned to 0 in the first array, whereas it is assigned to 1 in the second array as the key 0 is already taken by yellow.

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

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

Array
(
    [b] => brown
    [c] => blue
    [0] => red
)

Приклад #2 array_diff_assoc() example

Two values from key => value pairs are considered equal only if (string) $elem1 === (string) $elem2 . In other words a strict check takes place so the string representations must be the same.

<?php
$array1
= array(0, 1, 2);
$array2 = array("00", "01", "2");
$result = array_diff_assoc($array1, $array2);
print_r($result);
?>

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

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

Примітки

Зауваження: This function only checks one dimension of an n-dimensional array. It is possible to check deeper dimensions by using, for example, array_diff_assoc($array1[0], $array2[0]);.

Зауваження: Ensure arguments are passed in the correct order when comparing similar arrays with more keys. The new array should be the first in the list.

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