只计算PHP中多维数组的顶部单元格

时间:2015-05-11 09:05:48

标签: php arrays

我有一个数组如下。

我想要的只是计算这个数组的顶部单元格;如在0,1,2,3,4和5中那样。对于这个数组,我的计数应为6。

我怎样才能做到这一点?

我试过

count(array)sizeof(array),但它提供了大量数据。

Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [2011-11-18 00:00:00] => C
                )

            [1] => Array
                (
                    [2011-11-18 00:00:00] => I
                )

            [2] => Array
                (
                    [2011-11-18 00:00:00] => S
                )

        )

    [1] => Array
        (
            [0] => Array
                (
                    [2011-11-22 00:00:00] => C
                )

            [1] => Array
                (
                    [2011-11-22 00:00:00] => S
                )

        )

    [2] => Array
        (
            [0] => Array
                (
                    [2011-11-22 00:00:00] => C
                )

            [1] => Array
                (
                    [2011-11-22 00:00:00] => S
                )

        )

    [3] => Array
        (
            [0] => Array
                (
                    [2011-11-22 00:00:00] => C
                )

            [1] => Array
                (
                    [2011-11-22 00:00:00] => S
                )

        )
    [4] => Array
        (
            [0] => Array
                (
                    [2011-11-22 00:00:00] => C
                )

            [1] => Array
                (
                    [2011-11-22 00:00:00] => S
                )

        )

    [5] => Array
        (
            [0] => Array
                (
                    [2011-11-22 00:00:00] => C
                )

            [1] => Array
                (
                    [2011-11-22 00:00:00] => S
                )

        )
)

1 个答案:

答案 0 :(得分:-2)

尝试:

count(array_column($array , 0));

您可以进一步阅读here

这可以在> = PHP 5

中找到