Picking up how many entries in a json array

file-get-contents, html, json, php

Solution

Use `.length`

In Javascript

jsonObj['summary'].length

In PHP

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

Problem

I use 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's an excerpt of what it's taking from ``` { "summary" : [ [ 1, "PHI (A)", 14 ] [ 2, "TOR (A)", 8 ] ] } ``` At the moment only 2 weeks exist. 1 new entry will be added every week. How do I code something to say "loop for however many weeks/entries exist"? Pretty much what I want to do is put this info into a HTML table and I want the code to know how many weeks are in there. There will be 1 row of data for each week. Let me know if this isn't clear.. and thanks!

Original source