Jump to content

Compare selectors


elabx
 Share

Recommended Posts

Is there a smart wat to go about comparing two selectors to see if they are exactly the same?

I want to iterate through a group of pages with selector fields, and compare each field selector string to another one coming in through $input->get

eg. 

"baths>1, template=listing"  == "template=listing, baths>1" //should return true.

I've seen that this  (Selectors:: keyValueStringToArray) static helper just handles "=" operator and discards other selectors with a different operator when converting the selectors to an array. (my objective was to compare both arrays)

Link to comment
Share on other sites

Here's a try:

<?php

echo (selectorsMatch("baths>1, template=listing", "template=listing, baths>1")) ? "Match" : "No match";

function selectorsMatch($sel1, $sel2) {
	$s1 = new Selectors($sel1);
	$s1->sort('field');
	$s2 = new Selectors($sel2);
	$s2->sort('field');
  	return "$s1" == "$s2";
}

Not sure how this behaves with OR-groups, but it should be fine for simple AND selectors.

  • Like 2
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...