Jump to content

Compare two pagefields


Vayu Robins
 Share

Recommended Posts

Hi.

I need to compare two pagefields. I tried this:

$page->locations->has($user->locations)

But this doesn't work. I need to compare them and find out if the $page->locations has one or more of the same locations as the $user->locations. Hope it makes sense. :-)

Link to comment
Share on other sites

PageArray::has() only accepts a single object. You need a loop, here's an example:

$found = false;
foreach ($user->locations as $location) {
  if ($page->locations->has($location) {
    $found = true;
    break;
  }
}

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...