[thelist] PHP + XML + Array problem
Emma Jane Hogbin
emmajane at xtrinsic.com
Thu Mar 20 11:20:20 CST 2003
On Thu, Mar 20, 2003 at 10:53:10AM -0600, Burhan Khalid wrote:
> I have managed to get PHP to make an array from this file that's
> of this format (print_r() output) :
I did this earlier this week...lemme see if I can find what I did...
Your structure:
> Array
> (
> [0] => Afghanistan
> [1] => Array
> (
> [NAME] => Afghanistan
> [URL] => AFG.xml
> )
> ...
> }
My structure (I'm pretty sure it's close enough...):
This array is called, $users and is accessed with $this->users.
Array
(
[820] => Array
(
[name] => Emma Hogbin
[1] => Array
(
[perms[1]] => Edit Security
)
[2] => Array
(
[perms[2]] => Edit Test
)
...
)
)
This is how I entered my data:
$this->users[820]["name"] = $admin["name"];
$this->users[820][$typeid] = array("perms[$typeid]" => $admin['type']);
$typeid = is the number that's *not* 820 which is used as a key.
So based on all of this, try access the URL like this:
$data = $arrayname["Afghanistan"]["URL"];
My loop doesn't really apply because I'm checking to see if the perms
entry matches another list so I use array_key_exists...AND I have named
keys...however, yours might look something like this if you were able to
get names into your keys:
foreach ($arrayCountryList as $country->$details) {
// for a named key:
$country = $details["name"];
// you could try: $country = $details[0];
if ($country == "Afghanistan") {
// Access the sub-arrays here:
$file = $details["URL"];
break; // I think that's the right way to end this loop
}
}
Maybe that will help a little?
emma :)
--
Emma Jane Hogbin
[[ 416 417 2868 ][ www.xtrinsic.com ]]
More information about the thelist
mailing list