I know there is array_unique
function, but I want to remove duplicates. Is there a built-in function or do I have to roll my own.
Example input:
banna, banna, mango, mango, apple
Expected output:
apple
You can use a combination of array_unique
, array_diff_assoc
and array_diff
:
array_diff($arr, array_diff_assoc($arr, array_unique($arr)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With