For example i have an array like this [-1,-1,-1,-1,-1,-1,2.5,-1,-1,8.3]
I want to count the element which are not -1 like except of the -1. Is there any function in php to get this ? One approach which i think is
Count the total array - count of the -1 in the array.
how can we achieve this.
P.S : please provide me a comment why this question deserve negative vote.
count()with array_filter(); or use an array_count_values() to count the -1 values$result = count(array_filter($myArray), function($value) { return $value != -1; });.... sorry that PHP doesn't provide acountExcludingValuesOfMinusOne()function so that you can make it a single function callin_array()would tell you if a value of-1exists in the array.... it doesn't count them for you