RE: [PHP] Tricky array question
| From: | Pablo Gosse | Date: | Thu, 01 Apr 2004 19:16:04 +0000 |
| Subject: | RE: [PHP] Tricky array question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-182060@lists.php.net to get a copy of this message | ||
Merlin wrote:
> Hi there,
>
> I am trying to get continent and country info out of an xml file.
> There is a continent element to each country element.
>
> Now I do have an array with the continent info and one with the
> country info. The goal is to be able to output all countries sorted
> after continents. So I do have: $results[]->countryContinent
> $results[]->countryName
>
> I tryed to group those values, to do array searches and more, but
> somehow it looks like that there must be a way more easy way to do
> this. Maybe someone has a good hint how to solve that.
>
> Thanx for any help,
>
> merlin
I would suggest parsing the XML data such that you have an array of
continents, and each element of said array is an array with two elements
- the first being the contintent name and the second array containing
all countries within that continent.
So, after parsing the file you would have:
$contintents[0] = array('North America',array('Canada','United
States','Mexico'));
$contintents[1] = array('South
America',array('Ecuador','Chile','Peru','Columbia','Brazil'));
etc. etc.
HTH.
Pablo.