Count number of values in array with a given value Count number of values in array with a given value arrays arrays

Count number of values in array with a given value


How about using array_count _values to get an array with everything counted for you?


Just an idea, you could use array_keys( $myArray, "" ) using the optional second parameter which specifies a search-value. Then count the result.

$myArray = array( "","","other","","other" );$length  = count( array_keys( $myArray, "" ));


I dont know if this would be faster but it's something to try:

$counter = 0;foreach($array as $value){  if($value === '')    $counter++;}echo $counter;