CKTIS / PHP
array_intersect_key()
Select first-array entries by keys present in every other array.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
array_intersect_key(array $array, array ...$arrays): arraySelect first-array entries by keys present in every other array. Values of those other arrays are ignored, including null. The result retains the source values and order. An empty allowlist removes all fields, which is important when projecting a record onto an optional set of columns.
Signature
array_intersect_key(array $array, array ...$arrays): array
Example output
{"id":8,"label":"R"}
Examples
<?php
$record = ['id'=>8,'label'=>'R','cost'=>17];
echo json_encode(array_intersect_key($record, ['label'=>null,'id'=>false]));
Result
{"id":8,"label":"R"}