How do I count how many tables have the same name in a multidimensional array with php?

advertisements

I have a multidimensional array, and I would have multiple arrays within it. Some of those arrays contain multiple arrays within them as well, and I would like to count how many arrays are within the second array(the date).

This is an example of the structure of the multidimensional array:

$_SESSION['final_shipping'][04/03/2010][book]
$_SESSION['final_shipping'][04/12/2010][magazine]
$_SESSION['final_shipping'][04/12/2010][cd]

This is the foreach statement I am currently using to count how many of the second array(the one with the dates) exists.

foreach($_SESSION['final_shipping'] as $date_key => $date_value) {
    foreach ($date_value as $product_key => $product_value) {
        echo 'There are ' . count($date_key) . ' of the ' . $date_key . ' selection.<br/>';
    }
}

It is currently outputting this:

There are 1 of the 04/03/2010 selection.
There are 1 of the 04/12/2010 selection.
There are 1 of the 04/12/2010 selection.

I would like it to output this:

There are 1 of the 04/03/2010 selection.
There are 2 of the 04/12/2010 selection.


Call count() on $date_value instead, since you want to count the number of items in the array value mapped to that key, not the size of the key itself.

foreach($_SESSION['final_shipping'] as $date_key => $date_value) {
    echo 'There are ' . count($date_value) . ' of the ' . $date_key . ' selection.<br/>';
}