Loop through children, but don't show duplicates

Hello Kirby Pros,

I have a list of companies that are organized as subpages.
Every company has a field called »country«.

On the parent page (companies) I loop through the subpages but just show the countries as kind of a mini-navigation.

But when there are 3 companies in Germany and I list all countries I just want to show Germany once, not 3 times.

What I am using now is:
foreach($page->children()->sortBy('country', 'asc') as $partner){ echo $partner->country(); }

Does anyone have a solution for me?

Thanks :slight_smile:

Wow I found a solution by accident:
pluck() has a parameter that’s called »unique«. That solved my problem.

foreach($page->children()->sortBy('country', 'asc')->pluck('country','',true) as $country){ echo $country; }

Wouldn’t work if I needed more information than just the country field though.