3

I have an array, and would like to get all the values like this [*][place], without duplicate results. The output should be looking like this :

Sønderjylland Nordjylland Sjælland

Array
    (
        [0] => Array
            (
                [place] => Sønderjylland
                [active] => Lagerarbejde
                [num] => 123
            )

        [1] => Array
            (
                [place] => Nordjylland
                [active] => Tømrer
                [num] => 124
            )

        [2] => Array
            (
                [place] => Sønderjylland
                [active] => Klejnsmed
                [num] => 125
            )

        [3] => Array
            (
                [place] => Sjælland
                [active] => Elektriker
                [num] => 126
            )
    )

1 Answer 1

5

You can use array_column, array_unique, array_filter, implode together.

echo implode(' ', array_filter(array_unique(array_column($yourArray, 'place'))));

array_column is supported for (PHP 5 >= 5.5.0, PHP 7)

If you are using older versions then a loop would help.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you very mauch, it is work well, how can I delete duplicate results?
The last function called shouldn't be array_column?
Ahh... Missed that.. Updated. Thanks!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.