php - Get nr of items in an array -
i have array has format:
array( info( date-today => '09/04/2013' ) clients( id => 1001, name => fred ) more_info( weather-today => "cloudy" ) )
but sometimes, receive data more clients:
array( info( date-today => '08/04/2013' ) clients( 0( id => 1001, name => fred ), 1( id => 1045, name => fritz ) ) more_info( weather-today => "sunny" ) )
i want count how many cients got returned, because need access client-data differently if there 1 or more one. tried several "count()" options, such as:
count(array['client'])
but of course if there 1 client, doesn't return 1, returns 2 (since there 2 items of client-data in array).
any tips?
you have find out whether $array['clients']
has numeric indices:
$size = count($array['clients']; if (count(array_filter(array_keys($array['clients']), 'is_int')) == $size) { return $size; } else { return 1; }
alternatively, use existence of one numeric index condition:
if (isset($array['clients'][0])) { return count($array['clients']); } else { return 1; }
Comments
Post a Comment