PHP Count Number of True Values in a Boolean Array
I would use array_filter.
$array = array(true, true, false, false);echo count(array_filter($array));//outputs: 2
http://codepad.viper-7.com/ntmPVY
Array_filter will remove values that are false-y (value == false). Then just get a count. If you need to filter based on some special value, like if you are looking for a specific value, array_filter accepts an optional second parameter that is a function you can define to return whether a value is true (not filtered) or false (filtered out).
Try this approach :
<?php$array = array(1, "hello", 1, "world", "hello");print_r(array_count_values($array));?>
Result :
Array( [1] => 2 [hello] => 2 [world] => 1)