abmcr Posted September 30, 2017 Share Posted September 30, 2017 I need retrieve a list DISTINCT of values of a field (city) in a selector. now i have create a foreach Cycle for get the pages $arr=array(); $p=$pages->find(...); foreach($p as $el){ $arr[]=$el->city; } //now unique... But there is a most efficient way? thank in advance Link to comment Share on other sites More sharing options...
abdus Posted September 30, 2017 Share Posted September 30, 2017 Not necessarily a faster way (I haven't tested its performance), but you can do $uniques = array_unique($p->explode('city')): Link to comment Share on other sites More sharing options...
dragan Posted September 30, 2017 Share Posted September 30, 2017 maybe you could use this? http://cheatsheet.processwire.com/pagearray-wirearray/getting-items/a-unique/ Link to comment Share on other sites More sharing options...
abdus Posted September 30, 2017 Share Posted September 30, 2017 That wouldn't work here though. That method filters out the duplicate elements, not the elements that have the same field value. Link to comment Share on other sites More sharing options...
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