Jump to content

Select DISTINCT values of a fields in a pages selector


Recommended Posts

Posted

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

Posted

Not necessarily a faster way (I haven't tested its performance), but you can do

$uniques = array_unique($p->explode('city')):

 

Posted

That wouldn't work here though. That method filters out the duplicate elements, not the elements that have the same field value.

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
  • Recently Browsing   0 members

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