Stack Exchange
Count only the top cells of a multi dimensional array in PHP
I have an array as following.
What I want is to just count the top cells of this array; as in 0,1,2,3,4 and 5. So for this array I should have a count of 6.
How can I achieve that?
I tried 
count(array) and sizeof(array), but it gives a large number.
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
                )

        )
)


Have you tried count($array, 0) ? The second parameter specifies whether count should work or not with multi-dimensional arrays.

where's the codes? count($array) should have yielded 6

i didn't get any problem.It works well count($array);

Try:
count(array_column($array , 0));

You can read further here
This is available in >= PHP 5

No explanation or description provided. Seems like more of a comment. Why should this work when count() allegedly didn't?

maybe useful for those of us on earlier versions: Provides functionality for array_column() to projects using PHP earlier than version 5.5.
