note 120820 deleted from function.array-diff by cmb
| From: | cmb@php.net | Date: | Sun, 13 Oct 2019 16:29:48 +0000 |
| Subject: | note 120820 deleted from function.array-diff by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212649@lists.php.net to get a copy of this message | ||
Note Submitter: james dot PLZNOSPAM at bush dot cc
----
If you want a simple way to show values that are in either array, but not both, you can use this:
<?php
function arrayDiff($A, $B) {
$intersect = array_intersect($A, $B);
return array_merge(array_diff($A, $intersect), array_diff($B, $intersect);
}
?>
If you want to account for keys, use array_diff_assoc() instead; and if you want to remove empty
values, use array_filter().