我正在尝试查看此数组的大小是6
还是更多。我在计算第二级(size=10
)。什么是最简单的方法?
这里是倾销:
ARRAY (SIZE=1)
0 =>
ARRAY (SIZE=10)
'ID' => INT 35
'ALT' => STRING '' (LENGTH=0)
'TITLE' => STRING 'FD-7' (LENGTH=4)
'CAPTION' => STRING 'THIS IS THE FIFTH CAPTION FOR THE PHOTOGRAPH.' (LENGTH=45)
'DESCRIPTION' => STRING '' (LENGTH=0)
'MIME_TYPE' => STRING 'IMAGE/JPEG' (LENGTH=10)
'URL' => STRING 'HTTP://FASHION-DETAIL.DEV/WP-CONTENT/UPLOADS/2014/02/FD-7.JPG' (LENGTH=61)
'WIDTH' => INT 432
'HEIGHT' => INT 650
'SIZES' =>
ARRAY (SIZE=9)
'THUMBNAIL' => STRING 'HTTP://FASHION-DETAIL.DEV/WP-CONTENT/UPLOADS/2014/02/FD-7.JPG' (LENGTH=61)
'THUMBNAIL-WIDTH' => INT 63
'THUMBNAIL-HEIGHT' => INT 96
'MEDIUM' => STRING 'HTTP://FASHION-DETAIL.DEV/WP-CONTENT/UPLOADS/2014/02/FD-7.JPG' (LENGTH=61)
'MEDIUM-WIDTH' => INT 432
'MEDIUM-HEIGHT' => INT 650
'LARGE' => STRING 'HTTP://FASHION-DETAIL.DEV/WP-CONTENT/UPLOADS/2014/02/FD-7.JPG' (LENGTH=61)
'LARGE-WIDTH' => INT 432
'LARGE-HEIGHT' => INT 650
答案 0 :(得分:1)
为count()
申请COUNT_RESURSIVE
标记:
$result = count($array, COUNT_RECURSIVE);
- 整个阵列。如果您只想计算某个元素,请将其传递给:
//$key is your element's index
$result = count($array[$key]);
最后,要获得第二级的计数,您可以申请:
$array = [
['foo', 'bar'],
['baz'],
[],
['bee', 'feo']
];
$result = array_sum(array_map('count', $array));//5