What function is used to obtain the number of keys whose values are not empty in the array? For example, Array (& nbsp; [0] & nbsp ;=& gt; & nbsp; aa & nbsp; & nbsp; [1] & nbsp ;=& gt; & nbsp; bb & can you tell me how many functions are used to obtain the number of keys in an array that are not empty?
For example, array:
Array
(
[0] => aa
[1] => bb
[2] => cc
[3] =>
)
If count is used, the result is 4, and the key with no value is included. But do I want to get the number of keys whose values are not empty? It should be 3. is there any function that can be implemented?
------ Solution --------------------
$arr = array (
0 => 'aa',
1 => 'bb',
2 => 'cc',
3 => ''
);
function filter_empty($var) {
return ! empty ( $var );
}
echo count ( array_filter ( $arr, 'filter_empty' ) );
------ Solution --------------------
Print_r (count (array_filter ($ arr )));
/*
Manual
Array array_filter (array $ input [, callback $ callback])
If the callback function is not provided, array_filter () deletes all entries in the input that are equal to FALSE.
The null Boolean value is false.
*/