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
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
PHP.net http://php.net/manual/en/function.array-unique.php
New solution:
Only partially relevant to this specific question - but I created this function from Gumbo's answer for multi dimensional arrays:
In this example, I had cached statuses and each one other than the default was 0 (the default was 1). I index the
default
array from the IDs, and then turn it into a string. So to be clear - the returned result of this is the ID of the default status providing it's in the same part of the multi dimensional array and not the key of itIf you want to only leave values in the array that are already unique, rather than select one unique instance of each value, you will indeed have to roll your own. Built in functionality is just there to sanitise value sets, rather than filter.