在以下示例中显示内部数组值的计数

时间:2016-07-18 13:17:07

标签: php

我有以下数组我想显示内部数组值的数量请帮帮我。

Array
(
    [e1549b20-4cad-11e6-85b4-73d5cb14d4fe] => Array
        (
            [a029e160-4337-11e6-8db4-ad7de57838b4] => Array
                (
                    [0] => b46b70a2-481a-11e6-8b19-00262d644487
                    [1] => b4696a1e-481a-11e6-8b19-00262d644487
                )

            [40eca780-48ef-11e6-8a04-eb9fe0a25fc5] => Array
                (
                    [0] => b46b70a2-481a-11e6-8b19-00262d644487
                    [1] => b4696a1e-481a-11e6-8b19-00262d644487
                )

            [e5926390-44cf-11e6-bc85-19a184fbd10f] => Array
                (
                    [0] => b4696a1e-481a-11e6-8b19-00262d644487
                )

            [51a44c00-4a53-11e6-81fe-313fe319f95b] => Array
                (
                    [0] => b4696a1e-481a-11e6-8b19-00262d644487
                )

        )

)

1 个答案:

答案 0 :(得分:0)

请尝试使用此功能:

function getCount($arr, $count = 0) {
foreach ($arr as $value) {
    if (is_array($value)) {
        $count = getCount($value, $count);
    } else {
        $count = $count + 1;
    }
}
return $count;

}

echo getCount($ arr);