I have an array
.Its have positive, negative and zero value.Now i want to count those number of positive, negative and zero value then divided each group by number of array count.I have tried below way:
<?php
$arr = ['-4','3','-9','0','4','1'];
$countNum = count($arr);
//print_r($countNum);
foreach ($arr as $key => $value) {
if ($value<0) {
continue;
}elseif($value==0){
continue;
}else{
$result = $value/$countNum;
echo $result."</br>";
}
}
?>
Output is :
0.5
0.66666666666667
0.16666666666667
But i want and should be:
for positive, 3/6=0.500000
for negative, 2/6=0.333333
for zero, 1/6=0.166667