Getting the right value of a multidimentional array...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Wolf_22
Forum Contributor
Posts: 159
Joined: Fri Dec 26, 2008 9:43 pm

Getting the right value of a multidimentional array...

Post by Wolf_22 »

Forgive me if I ask this in a stupid or naive way, but I'm having some problems with a multidimensional array that I'm working with and I can't seem to figure out how to pinpoint the correct sub-array using a foreach statement. The code I'm working with is below:

Code: Select all

 
foreach($questions[$choices][$i] as $key => $value){
    echo $key.'<br />';
}
 
$questions has the following "sub arrays" in it: $text, $choices, and $answer. If $i is merely a counter variable (sentinel variable from a FOR statement), then how would I target or cycle through each value within the $choices sub array?
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Getting the right value of a multidimentional array...

Post by Mark Baker »

Code: Select all

 
foreach($questions['choices'] as $key => $value){
    echo $key.'<br />';
}
 
Post Reply