如何使用在php中分离的键值来获取嵌套数组计数

This is my array

Array
(
    [2] => Array
        (
            [0] => Array
                (
                    [id] => 2
                    [res_id] => 1
                    [grand_total] => 303.42
                    [time] => 2016-07-28 11:04:38 AM
                    [status] => 0
                )

            [1] => Array
                (
                    [id] => 2
                    [res_id] => 1
                    [grand_total] => 303.42
                    [time] => 2016-07-28 11:04:38 AM
                    [status] => 0
                )

        )

    [1] => Array
        (
            [0] => Array
                (
                    [id] => 1
                    [res_id] => 1
                    [grand_total] => 303.42
                    [time] => 2016-07-28 11:04:17 AM
                    [status] => 0
                )

        )

)

From this I need sub array count i.e., the array having two indexes such as 2 & 1 from this 2 & 1 there are some nested arrays found such as 0 & 1 for each

Here,I need array count as follows

Array
(
    [2] => Array
        (
            [count] = 2
        )

    [1] => Array
        (
            [count] = 1
        )

)

How should I get this..

Someone help me out of this...

Thank you..

It is very easy foreach your array and use count or sizeof function.

$desiredArray = array();
foreach ($myarray as $key => $value) {
    $desiredArray [$key] ['count'] = sizeof ($value); 
}

print_r ($desiredArray);

The output will be as your desired output

Array
(
    [2] => Array
        (
            [count] = 2
        )

    [1] => Array
        (
            [count] = 1
        )

)

It's simple, and is better to create new array where you can save count of elements of main array items:

$counts = array();
foreach ($array as $k => $values) {
    $counts[$k] = count($values);
}

print($counts); // gives desired result

Also you don't need to have extra array for the $counts array, what you get is:

array (
    2 => 2,
    1 => 1
)