CKTIS / PHP
array_diff()
Keep entries of the first array whose values are absent from every comparison array.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
array_diff(array $array, array ...$arrays): arrayKeep entries of the first array whose values are absent from every comparison array. Original keys survive and duplicate values in the first array can remain. Scalar values compare by their string representations, so a numeric string can match an integer. Use this for exclusion lists of simple values.
Signature
array_diff(array $array, array ...$arrays): array
Example output
{"b":7,"c":7}
Examples
<?php
$stock = ['a'=>4, 'b'=>7, 'c'=>7];
echo json_encode(array_diff($stock, ['4']));
Result
{"b":7,"c":7}