Example 1 — Finding Values That Are Not Shared
Remove from the first list every value that also exists in the second list.
<?php
$all = [1, 2, 3, 4, 5];
$remove = [2, 4];
print_r(array_diff($all, $remove)); How It Works
- array_diff() looks at each value in $all.
- The values 2 and 4 are also in $remove, so they are left out.
- The values 1, 3 and 5 are kept with their original keys 0, 2 and 4.
- The gaps in the keys show that nothing was re-indexed.

