elabx Posted June 12, 2018 Posted June 12, 2018 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)
BitPoet Posted June 12, 2018 Posted June 12, 2018 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. 2
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now