Re: [PHP] Tricky array question

2004-04-01 Thread Kelly Hallman
Apr 1 at 8:13pm, Merlin wrote:
> 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.
>
> $results[]->countryContinent
> $results[]->countryName

First, although this does work, I don't know if it's what you want to do.
You'll end up with a structure like this:

Array (
[0] => stdClass Object
( [countryContinent] => North America )
[1] => stdClass Object
( [countryName] => Canada ) )

Not very useful, as you've found.

> 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.

I think this is along the lines of what you want to do:

$continent = 'North America';
$landmass[$continent][] = 'Canada';
$landmass[$continent][] = 'United States';
$landmass[$continent][] = 'Mexico';

$continent = 'Asia';
$landmass[$continent][] = 'Japan';
$landmass[$continent][] = 'China';
$landmass[$continent][] = 'Korea';

// sort continents then countries
ksort($landmass); // use ksort() to sort by key
foreach($landmass as $conti => $cntry) { sort($landmass[$conti]); }

print_r($landmass);

There's your array, just loop over it as you like, to do your output.
If you're reading an XML file, you might look into PEAR, which has 
packages for parsing and building data structures of XML data.

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Tricky array question

2004-04-01 Thread Pablo Gosse
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.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Tricky array question

2002-02-05 Thread Niklas Lampén

Ahem... So you want to have a two dimensional variable?

"; 
?>


Is this what you are looking for?


Niklas

-Original Message-
From: Andy [mailto:[EMAIL PROTECTED]] 
Sent: 5. helmikuuta 2002 12:54
To: [EMAIL PROTECTED]
Subject: Re: [PHP] Tricky array question


This was just an error in my explenation I ment categories.

Meanwhile I tryed var vars, but it does not work for any reason?!?!?

My code looks like:

 $field = $categories[0]."[0]";
 echo $field;// returns glacier[0]
 echo 'var '.$$field.''; // returns bluddy nothing
 echo $categories[0]; // returns  glacier
 echo $glacier[0];// returns 110

Does anybody know how to get the 110 out of the array?

Thanx for any help,

Andy



"Niklas lampén" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
008101c1ae2d$a9df7580$ba93c5c3@Niklas">news:008101c1ae2d$a9df7580$ba93c5c3@Niklas...
> It should be $category[0] = $glacier;
> ^--- ERROR in you code
>
>
> Niklas
>
>
> -Original Message-
> From: Andy [mailto:[EMAIL PROTECTED]]
> Sent: 5. helmikuuta 2002 11:59
> To: [EMAIL PROTECTED]
> Subject: [PHP] Tricky array question
>
>
> Hi there,
>
> I have a tricky array question.
>
> My app is passing via post a array variable called glacier. Now I am 
> checking for the content of this array. Because there are more of 
> those arrays, I am getting all the names out of a db.
>
> How is it possible to get the value and keep the name of the array 
> dynamic?
>
> e.g:
> Array name passed by post is: $glacier
> //
> contains e.g. $glacier[0] = testname
> Array with category names coming out of db is:   $category // contains
> e.g.
> $category[0] = glacier
>
>  echo $categories[0]; // returns glacier
>  echo $glacier[0];  // returns testname
>
> I tryed $categories[0][0] but it returns only the first letter of 
> glacier
> (g)
>
> Any ideas??
>
> Thanx, Andy
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Tricky array question

2002-02-05 Thread Andy

This was just an error in my explenation I ment categories.

Meanwhile I tryed var vars, but it does not work for any reason?!?!?

My code looks like:

 $field = $categories[0]."[0]";
 echo $field;// returns glacier[0]
 echo 'var '.$$field.''; // returns bluddy nothing
 echo $categories[0]; // returns  glacier
 echo $glacier[0];// returns 110

Does anybody know how to get the 110 out of the array?

Thanx for any help,

Andy



"Niklas lampén" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
008101c1ae2d$a9df7580$ba93c5c3@Niklas">news:008101c1ae2d$a9df7580$ba93c5c3@Niklas...
> It should be $category[0] = $glacier;
> ^--- ERROR in you code
>
>
> Niklas
>
>
> -Original Message-
> From: Andy [mailto:[EMAIL PROTECTED]]
> Sent: 5. helmikuuta 2002 11:59
> To: [EMAIL PROTECTED]
> Subject: [PHP] Tricky array question
>
>
> Hi there,
>
> I have a tricky array question.
>
> My app is passing via post a array variable called glacier. Now I am
> checking for the content of this array. Because there are more of those
> arrays, I am getting all the names out of a db.
>
> How is it possible to get the value and keep the name of the array
> dynamic?
>
> e.g:
> Array name passed by post is: $glacier
> //
> contains e.g. $glacier[0] = testname
> Array with category names coming out of db is:   $category // contains
> e.g.
> $category[0] = glacier
>
>  echo $categories[0]; // returns glacier
>  echo $glacier[0];  // returns testname
>
> I tryed $categories[0][0] but it returns only the first letter of
> glacier
> (g)
>
> Any ideas??
>
> Thanx, Andy
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Tricky array question

2002-02-05 Thread Niklas Lampén

It should be $category[0] = $glacier;
^--- ERROR in you code


Niklas


-Original Message-
From: Andy [mailto:[EMAIL PROTECTED]] 
Sent: 5. helmikuuta 2002 11:59
To: [EMAIL PROTECTED]
Subject: [PHP] Tricky array question


Hi there,

I have a tricky array question.

My app is passing via post a array variable called glacier. Now I am
checking for the content of this array. Because there are more of those
arrays, I am getting all the names out of a db.

How is it possible to get the value and keep the name of the array
dynamic?

e.g:
Array name passed by post is: $glacier
//
contains e.g. $glacier[0] = testname
Array with category names coming out of db is:   $category // contains
e.g.
$category[0] = glacier

 echo $categories[0]; // returns glacier
 echo $glacier[0];  // returns testname

I tryed $categories[0][0] but it returns only the first letter of
glacier
(g)

Any ideas??

Thanx, Andy




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Tricky array question

2002-02-05 Thread Edward van Bilderbeek - Bean IT

try using something like this:

$varname = $categories[0];

echo ${$varname}[0];



Greets,

Edward



"Andy" <[EMAIL PROTECTED]> wrote in message
news:<[EMAIL PROTECTED]>...

> Hi there,

>

> I have a tricky array question.

>

> My app is passing via post a array variable called glacier. Now I am

> checking for the content

> of this array. Because there are more of those arrays, I am getting all
the

> names out of a db.

>

> How is it possible to get the value and keep the name of the array
dynamic?

>

> e.g:

> Array name passed by post is: $glacier //

> contains e.g. $glacier[0] = testname

> Array with category names coming out of db is: $category // contains e.g.

> $category[0] = glacier

>

> echo $categories[0]; // returns glacier

> echo $glacier[0]; // returns testname

>

> I tryed $categories[0][0] but it returns only the first letter of glacier

> (g)

>

> Any ideas??

>

> Thanx, Andy

>

>

>

>

> --

> PHP General Mailing List (http://www.php.net/)

> To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php