CKTIS / PHP
array_intersect_assoc()
Retain an entry from the first array only when every comparison array has the same key together with a matching value.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
array_intersect_assoc(array $array, array ...$arrays): arrayRetain an entry from the first array only when every comparison array has the same key together with a matching value. A value under a different key is insufficient. Scalar values compare by their string representations. It is suitable for finding common settings in flat configuration maps.
Signature
array_intersect_assoc(array $array, array ...$arrays): array
Example output
{"port":80}
Examples
<?php
$local = ['port'=>80, 'active'=>1, 'zone'=>'A'];
echo json_encode(array_intersect_assoc($local, ['port'=>'80','enabled'=>1]));
Result
{"port":80}