Forum Moderators: coopster

Message Too Old, No Replies

Printing one value from nested array

Using the value as a variable

         

deMorte

8:31 am on May 22, 2008 (gmt 0)

10+ Year Member



I have an array within array ($uparray["$lowarray"]) and I want to print out a single value from the nested $lowarray and use it as a variable in a loop.
I figured that since the keys are numeric in the $lowarray something along the lines of:

$values_in_array = count($uparray["$lowarray"])
for($i=0; $i<$values_in_array-1; $i++) {
print $uparray["$lowarray[$i]"];
}

This didn't work. Loop runs as it should, array has the right values but nothing is printed out. Is there something wrong with my syntax or do I need a function to print.

MattAU

9:48 am on May 22, 2008 (gmt 0)

10+ Year Member



You're on the right track.

Most likely the problem lies with $uparray["$lowarray[$i]"];

Nested arrays are all a part of the parent array... Using $uparray[$lowarray][$i]; instead should work. Also note that you don't need the quote marks when you're using a variable, they're only needed for a string.

deMorte

10:03 am on May 22, 2008 (gmt 0)

10+ Year Member



Worked like a charm.

Thank you very much.