lets say i have an array like: Array ( [0] => [1] => 2 [2] => 3 [3] => 3 [4] => 3 ) now i want to count the total number of items in the array so i use: count($items) however that counts the [0] key which has no value, is there a way to only count fields with a value.
Well, an empty value is still a value. If you want to check for empty values, you probably will need to loop through the array to check each value like so: $count = 0; foreach ($array as $val) { if ($val) $count++; } PHP: