Array_unique removing fields it shouldn't

here is the arrays -

$reply = $stmt->all();
		$usList = array_unique($reply);

Open in new window


this is created from a table of regions.

what i am doing is taking all the time zone regions within the states to create a list of people from the different regions. now some people will be from the same region which makes duplications in the array. i need to only keep one per region so i tried using array)unique but it is removing fields which aren't dups.

dupe array contents -

Array(25)
0
:
{TIME_ZONE: "America/New_York"}
1
:
{TIME_ZONE: "America/New_York"}
2
:
{TIME_ZONE: "America/New_York"}
3
:
{TIME_ZONE: "America/New_York"}
4
:
{TIME_ZONE: "America/New_York"}
5
:
{TIME_ZONE: "America/New_York"}
6
:
{TIME_ZONE: "America/New_York"}
7
:
{TIME_ZONE: "America/New_York"}
8
:
{TIME_ZONE: "America/New_York"}
9
:
{TIME_ZONE: "America/New_York"}
10
:
{TIME_ZONE: "America/New_York"}
11
:
{TIME_ZONE: "America/New_York"}
12
:
{TIME_ZONE: "America/New_York"}
13
:
{TIME_ZONE: "America/New_York"}
14
:
{TIME_ZONE: "America/New_York"}
15
:
{TIME_ZONE: "America/New_York"}
16
:
{TIME_ZONE: "America/New_York"}
17
:
{TIME_ZONE: "America/New_York"}
18
:
{TIME_ZONE: "America/New_York"}
19
:
{TIME_ZONE: "America/New_York"}
20
:
{TIME_ZONE: "America/New_York"}
21
:
{TIME_ZONE: "America/New_York"}
22
:
{TIME_ZONE: "America/North_Dakota/Center"}
23
:
{TIME_ZONE: "America/Toronto"}
24
:
{TIME_ZONE: "America/Toronto"}

Open in new window



result after array_unique -

Array(1)
0
:
{TIME_ZONE: "America/New_York"}

Open in new window


as seen there is atleast two field on that array that should be in the sorted array. but they arent.
Alex LordAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris StanyonWebDevCommented:
Can't see anything fundamentally wrong with your code.

I would double check what $stmt->all() is returning (is it JSON etc.), and then just var_dump out the 2 versions of your array (more as a sanity check than anything else):

$reply = $stmt->all();
var_dump($reply);
var_dump(array_unique($reply));

Open in new window

See what that gives you.
0
Alex LordAuthor Commented:
hey Chris Stanyon

that just gives me error in the ajax response.

it is a strange one as im sure they just dragged form the database and stored as a string to be matched up later on down the line
0
Alex LordAuthor Commented:
	$stmt = new Database();

		$query = "SELECT TIME_ZONE FROM TXT2GIVE_CHARITY_DETAILS WHERE ID = :clientID";
		$stmt->query( $query );
		$stmt->bind( ':clientID', $clientId);
		$stmt->execute();
		$result = $stmt->all();

		

		$stmt = new Database();

		$query = "SELECT TIME_ZONE FROM TXT2GIVE_CHARITY_DETAILS WHERE TIME_ZONE LIKE  '%America%'";
		$stmt->query( $query );
		$stmt->bind( ':usa', 'America');
		$stmt->execute();
		$reply = $stmt->all();

Open in new window


here is a bigger picture,  first one gets the time zone of the user and the 2nd one gets all the time zones that are in america, what i am trying to do is get only one of each zone and match the two results to see if the client is within any of the american zones if  that makes sense
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Chris StanyonWebDevCommented:
OK Alex,

Would it not make more sense to just query the database for TIME_ZONE where the client ID matches AND the TIME_ZONE is in America. If no results are found the user isn't in America.

Alternatively you could just add a DISTINCT to your second query:

SELECT DISTINCT TIME_ZONE FROM TXT2GIVE_CHARITY_DETAILS ...

That would only pull out the unqiue timezones from the DB.

Third alternative is to keep the code as it is, and then just run an in_array($result, $reply). That will return TRUE if the Client TimeZone is in the List of TimeZones - otherwise it will return FALSE.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Alex LordAuthor Commented:
Hey Chris Stanyon

im going to give first option a go and will let you know.
0
Alex LordAuthor Commented:
The First option Chris looked and worked the best i just use true or false on ajax return.
0
Chris StanyonWebDevCommented:
Great stuff Alex,

Always good to have options :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.