1

What am I doing wrong with this? If I just run this:

$region = EM_Locations::get(array('orderby'=>'region_name'));

all is good. However when I add in the array_unique:

$region = EM_Locations::get(array('orderby'=>'region_name'));
$reg = array_unique($region)

It breaks and get "EM_Location could not be converted to string"

2 Answers 2

1

array_unique() sorts the values treated as string, two elements are considered equal if and only if (string) $elem1 === (string) $elem2.

You can add __toString() method for the EM_Location class.

Sign up to request clarification or add additional context in comments.

Comments

1

From the documentation for array_unique:

array_unique() sorts the values treated as string at first, then will keep the first key encountered for every value, and ignore all following keys.

This means that the values must be converted to a string for comparison, but your values appear to be of type EM_Location, which PHP can't figure out how to convert to a string.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.