Php 如何计算JSON对象数组中的数组长度?
我有一个JSON(第a行),如下所示,我想计算JSON对象数组中的项数Php 如何计算JSON对象数组中的数组长度?,php,arrays,json,Php,Arrays,Json,我有一个JSON(第a行),如下所示,我想计算JSON对象数组中的项数 $fp = fopen('../feeds/ptp-ess_landing.json', 'w'); fwrite($fp, json_encode($output)); fclose($fp); logActivity(); if(file_exists('../feeds/ptp-ess_landing.json')){ $data = json_decode(file_g
$fp = fopen('../feeds/ptp-ess_landing.json', 'w');
fwrite($fp, json_encode($output));
fclose($fp);
logActivity();
if(file_exists('../feeds/ptp-ess_landing.json')){
$data = json_decode(file_get_contents('../feeds/ptp-ess_landing.json'));
}
{"toggle_multi_tiles":["0","1"]} // Line A
现在是2。它也可以是三个,有时也可以是四个
这就是我尝试过的:
$data->toggle_multi_tiles.length; // Line B
在执行echo$data->toggle_multi_tiles.length
它返回的Arraylength
不是我得到的正确输出
问题陈述:
我想知道我应该在上面的php代码的B行中做些什么更改,以便它返回2 使用
count
计算PHP数组中的元素数
count ( $data->toggle_multi_tiles ) ;