Check if field object the same

I have a Pages Object. For each page in the Pages Object I would like to check the field object of its source: URL field. If the URL is the same I would like to remove it or skip it in a foreach loop.

I have not included any code, because I am stuck at the beginning. I understand something like array_unique could help me.

Thank you!

<?php
$urls = [];
foreach ($pages as $page) {
    if (in_array($page->source(), $urls)) {
        continue;
    }
    $urls[] = $page->source();
    //  do something here for all relevant pages
}

Or

$groups = $pages->groupBy('source');

foreach ($groups->map(fn($item) => $item->first()) as $firstOfGroup) {
  dump($firstOfGroup->title());
}

Thank you, I just tested your second option and it worked great!

I also got the desired result with this way too:

      <?php
      $arr = array();
      foreach ($page->getArtworks() as $artwork) {
          $arr[] = $artwork->source();
      }
      // check items are unique
      $unique_data = array_unique($arr);
      ?>
      <?php
      // now use foreach loop on unique data
      foreach($unique_data as $val): ?>
        <a href="<?= $val ?>">Further reading: <?= $val->parent()->title() ?></a>
      <?php endforeach ?>