Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何计算JSON对象数组中的数组长度?_Php_Arrays_Json - Fatal编程技术网

Php 如何计算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

我有一个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_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 ) ;