Page 1 of 1

Array_Unique Php

Posted: Fri Dec 19, 2008 4:51 am
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.

Re: Array_Unique Php

Posted: Fri Dec 19, 2008 6:29 am
by Mark Baker

Code: Select all

 
$locationNames = array();
foreach ($xmlfile->Hotel as $hotel){
   $locationNames[] = $hotel->Location;
}
$uniqueLocationNames = array_unique($locationNames);
 
 

Re: Array_Unique Php

Posted: Tue Dec 23, 2008 5:12 am
by emilie6709
Brilliant! Thanks so much!