Choosing the number of records in a json array

I am using the following code to extract information from a json page.

$str = file_get_contents('http://fantasy.mlssoccer.com/web/api/elements/498/');
$jsonarray = json_decode($str, true);

$week1 = $jsonarray['fixture_history']['summary'][0][2];
$week2 = $jsonarray['fixture_history']['summary'][1][2];

Here is an excerpt from what she takes from

{ "summary" : 
    [ 
        [ 1, "PHI (A)", 14 ]
        [ 2, "TOR (A)", 8 ]
    ]
}

At the moment, there are only 2 weeks. 1 new entry will be added every week. How do I encode something to say "a loop for any weeks / entries exists?"

Quite a lot of what I want to do is put this information in an HTML table, and I want the code to know how many weeks there are. For each week there will be 1 row of data.

Let me know if this is not clear .. and thanks!

+5
source share
2 answers

Use .length

In javascript

jsonObj['summary'].length

In php

echo count($jsonarray['fixture_history']['summary']);
+3
source

, count(), . , .

$arr_length = count($arr);
+1

All Articles