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!

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


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

foreach ($groups->map(fn($item) => $item->first()) as $firstOfGroup) {

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

I also got the desired result with this way too:

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