Array_Unique Php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
emilie6709
Forum Newbie
Posts: 3
Joined: Thu Dec 18, 2008 10:14 am

Array_Unique Php

Post by emilie6709 »

I'm new at php so my question might seem pretty basic to some of you.

I am trying to parse an xml doc (a list of hotels) using php. The idea is to create a page for each city and then one per hotel.

What I am trying to do is to create some array_unique to get all hotel in which city on the city page.

Here are the codes I am using: Does anyone has a better solution?

$citydata = "";
foreach ($xmlfile->Hotel as $hotel){
$locationname = ($hotel->Location);
$uniquelocations = array_unique($locationname);
$citydata .= "".$uniquelocations."<br />";
}

Cheers,
Em.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Array_Unique Php

Post by Mark Baker »

Code: Select all

 
$locationNames = array();
foreach ($xmlfile->Hotel as $hotel){
   $locationNames[] = $hotel->Location;
}
$uniqueLocationNames = array_unique($locationNames);
 
 
emilie6709
Forum Newbie
Posts: 3
Joined: Thu Dec 18, 2008 10:14 am

Re: Array_Unique Php

Post by emilie6709 »

Brilliant! Thanks so much!
Post Reply