Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

array_diff_assoc()

Find first-array entries for which no other array contains the same key and matching value.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

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

Find first-array entries for which no other array contains the same key and matching value. A matching value stored under a different key does not remove the entry. The comparison is shallow and scalar values compare by string representation, so this is useful for comparing flat attribute maps.

Signature

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

Example output

{"count":2,"mode":"auto"}

Examples

<?php
$saved = ['size'=>4, 'count'=>2, 'mode'=>'auto'];
echo json_encode(array_diff_assoc($saved, ['size'=>'4','other'=>2]));

Result

{"count":2,"mode":"auto"}

Sources