CKTIS / PHP
array_diff_key()
Remove entries of the first array whose keys occur in any comparison array.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
array_diff_key(array $array, array ...$arrays): arrayRemove entries of the first array whose keys occur in any comparison array. Contents of the matching fields play no role, even when a comparison value is null. This makes a field exclusion list independent of its stored values. Keys of the retained entries are preserved.
Signature
array_diff_key(array $array, array ...$arrays): array
Example output
{"sku":"A2","units":0}
Examples
<?php
$record = ['sku'=>'A2','internal'=>8,'units'=>0];
echo json_encode(array_diff_key($record, ['internal'=>null]));
Result
{"sku":"A2","units":0}