0

The array:

Array
(
[2010091907] => Array
    (
        [home] => Array
            (
                [score] => Array
                    (
                        [1] => 7
                        [2] => 17
                        [3] => 10
                        [4] => 7
                        [5] => 0
                        [T] => 41
                    )

                [abbr] => ATL
                [to] => 2
            )

How would I access abbr and display its value. Here's my PHP code:

     $json=json_decode($data,true);

     foreach ($json as $key => $date) {
         echo "Key: ".$key."; Value: ".$date."<br />";
         foreach ($date as $team) {
             echo "Team: ".$team."<br />";

         }
     }

3 Answers 3

1
echo $array[2010091907]['home']['abbr'];

would output

ATL

if you want to output just the singl value. Within your loop structure, JochenJung's got the fix below.

Sign up to request clarification or add additional context in comments.

Comments

1

Should be $team['abbr']

in your inner foreach()

Comments

0

Try this:

foreach ($arr as $key => $date) {
    echo "Key: ".$key."; Value: ".$date."<br />";
         foreach ($date as $team) {
             echo "Team: ".$team['abbr'];
         }     
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.