I've read plenty of previously asked questions about arrays but I'm just not able to get this to work :( My array looks like:-
Array
(
[1259] => Array
(
[status] => 0
[cond] => 0
)
[1461] => Array
(
[status] => 0
[cond] => 0
)
)
The keys vary depending on user input. All I'm currently trying to do is loop through the input and echo out the array contents alongside its parent arrays key.
My code is as follows:-
foreach($games as $key => $value) {
echo 'key: '.$key.' - ';
foreach( $value as $game){
echo $game["status"].' - '.$game["cond"].'<BR>';
}
}
This is incorrect because it is echoing the status and cond twice for each array item. I've also read that it is incorrect to use a foreach inside another foreach.
The following code is almost there but I'm having trouble echoing the array key with the status and cond information:-
foreach( $games as $game){
echo $game["status"].' - '.$game["cond"].'<BR>';
}
Is it possible to echo the array key (eg. 1259) in the above code?
Many thanks