How can I exclude null values from a count on an array? since count always includes null values in the counting!
count(array_filter($array, function($x) {return !is_null($x); })
function count_nonnull($a) {
$total = 0;
foreach ($a as $elt) {
if (!is_null($elt)) {
$total++;
}
}
return $total;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With