Is there anyway to count array if value > 10 without looping(foreach)?
$arr=array(5,7,11,67,4,12,15);
$wanted_output=4
Just use array_reduce
then you don't need count
echo array_reduce($arr, function ($a, $b) {
return ($b > 10) ? ++$a : $a;
}); // returns 4
$minVal = 10;
$counter = count(
array_filter(
$myArray,
function($value) use ($minVal) {
return $value > $minVal;
}
)
);
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