[英]Picking up how many entries in a json array
我使用以下代碼從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 ]
]
}
目前僅存在2周。 每周將添加1個新條目。 我如何編寫代碼來說“循環存在多少周/條目”?
我想要做的就是將這些信息放入HTML表格中,我希望代碼能夠知道有多少周。 每周將有1行數據。
如果不清楚,請告訴我..謝謝!
使用.length
在Javascript中
jsonObj['summary'].length
在PHP中
echo count($jsonarray['fixture_history']['summary']);
你需要的是count()
,它給你數組的長度。 在條件的for循環中使用它,你應該得到你的答案。
$arr_length = count($arr);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.