Forum Moderators: coopster

Message Too Old, No Replies

Nested arrays.

can't access the nested array!

         

Frasnko

6:21 am on Apr 6, 2007 (gmt 0)

10+ Year Member



when i print out the values of an array:

echo"<pre>";
print_r($values);
echo"</pre>";

i get this structure:

Array
(
[imgTitle] => dss
[imgDesc] => dsssssssssss
[imgKeys] =>
[imgMeta] =>
[btnUpload] => Upload
[filename] => Array
(
[name] => fridg.jpg
[type] => image/jpeg
[tmp_name] => /tmp/php5YSexL
[error] => 0
[size] => 17583
)

)

what i need to get is all the top level values (and that is not a problem), but i have not been able to grab the filename without looping through the values like this:

foreach ($values as $key=>$value) {
if($key == 'filename'){echo"IMAGE::::$value[name]";}
}

which seems like a total waste of resources! I have tried lots of combos and i have not been able to directly access this value.

The most logical way that i can think of getting at this variable is: $values[filename][name]

but that gives me the following:
Array[name]

what am i missing?

eelixduppy

6:26 am on Apr 6, 2007 (gmt 0)



Welcome to WebmasterWorld, Frasnko!

It doesn't seem like you are missing anything. This should give you the desired result:


echo 'Filename: '.$values['filename']['name'];

If this doesn't work then your array must not be constructed as you think it is.

More on arrays here: [php.net...]

Frasnko

6:50 am on Apr 6, 2007 (gmt 0)

10+ Year Member



Thanks for the quick reply, i think that this file is a huge mess and i might be better off sleeping!
Thank you for taking a look at it - sometimes a second set of eyes can be a huge asset!