Php 获取json数组中有多少个条目

Php 获取json数组中有多少个条目,php,html,file-get-contents,json,Php,Html,File Get Contents,Json,我使用以下代码从json页面提取信息 $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]

我使用以下代码从json页面提取信息

$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];
下面是它的摘录

{ "summary" : 
    [ 
        [ 1, "PHI (A)", 14 ]
        [ 2, "TOR (A)", 8 ]
    ]
}
目前只有两周的时间。每周将添加1个新条目。我如何编写代码来表示“无论存在多少周/条目,都要循环”

我想做的就是把这些信息放到一个HTML表中,我想让代码知道其中有多少周。每周将有一行数据


如果这不清楚,请告诉我。。谢谢

使用
.length

Javascript中的

jsonObj['summary'].length
PHP中的

echo count($jsonarray['fixture_history']['summary']);
您需要的是,这将为您提供数组的长度。在for循环中使用它作为条件,你应该有你的答案

$arr_length = count($arr);

看来这就是我需要的。但是,在我的示例中如何使用它?我尝试了
echo$jsonarray['fixture_history']['summary'].length
并返回单词
数组长度
。有没有办法让它返回一个简单的数字?(在本例中应为2)@Cully参见未注明日期的答案。非常好。工作完美。对不起,我应该提到PHP。我对javascript知之甚少。谢谢!