Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP count items in a multi-dimensional array

As you can see from the following array, there are three elements that appear on Nov 18, and another two elements that appear on Nov 22. Can someone tell me how I can retrieve the counts of 3 and 2 respectively from this array? Basically, I want to end up with a result something like this:

Nov 18, 2011 = 3 items

Nov 22, 2011 = 2 items

Of course, the dates and the number of different dates will vary every time. Here is the 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
                )

        )

)
like image 301
DanielAttard Avatar asked Nov 27 '11 07:11

DanielAttard


1 Answers

You can use:

count($array, COUNT_RECURSIVE);

Count number of leaves in nested array tree

like image 167
emilie zawadzki Avatar answered Oct 18 '22 13:10

emilie zawadzki