Count () in php to get the length

1

It turns out that I have the following associative arrangements:

Array ( 
    [ItemID] => 192 
    [ItemName] => Ford 
    [IMEI] => 0080WEWE 
    [Status] => A 
)

When I use the count () method for that array the result is 4, because it counts the elements.

Now I have the following array:

Array ( 
   [0] => Array ( 
           [ItemID] => 173
           [ItemName] => Cheyene 
           [IMEI] => 207729471 
           [Status] => A
         )
   [1] => Array (
           [ItemID] => 191
           [ItemName] => Vento  
           [IMEI] => 008045840 
           [Status] => A 
         )
) 

When I draw the length of this array with the count () method the result is 2.

Now the question is how could I make it so that array 1 would result in 1 using count () or how can I know if my array is an array of arrays or just a common array that is obviously associative?

    
asked by José Gregorio Calderón 23.03.2018 в 20:47
source

1 answer

2

Using only count I think it's impossible, I would play at least with an if and comparing the recursive version of count vs the typical count:

if (count($array) == count($array, COUNT_RECURSIVE)) {
    echo 1;
} else {
    echo count($array);
}
    
answered by 23.03.2018 в 23:04