i want to get only not null values count in that array , if i use count()
or sizeof
it will get the null indexes also .
in my case
i have an array like this Array ( [0] => )
the count
is 1
. but i want to get the not null count , inthis case it should be 0
, how can i do this , please help............................
In order to remove empty elements from an array, filter() method is used. This method will return a new array with the elements that pass the condition of the callback function.
The count() function returns the number of elements in an array.
The is_null() function checks whether a variable is NULL or not. This function returns true (1) if the variable is NULL, otherwise it returns false/nothing.
PHP count() function is an in-built function available in PHP, which counts and returns the number of elements in an array. It also counts the number of properties in an object. The count() function may return 0 for the variable, which has been declared with an empty array or for the variable which is not set.
simply use array_filter() without callback
print_r(array_filter($entry));
$count = count(array_filter($array));
array_filter
will remove any entries that evaluate to false
, such as null
, the number 0
and empty strings. If you want only null
to be removed, you need:
$count = count(array_filter($array,create_function('$a','return $a !== null;')));
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