- array_intersect: documentation ( source)
- print_r: documentation ( source)
<?php
$hasil = 80;
$kecewa = array(0,40,65);
$biasa = array(40,65,80);
$puas = array(65,80,100);
$kb = array_intersect($kecewa, $biasa);
$bp = array_intersect($biasa, $puas);
print_r($kb);
print_r($bp);
// antara 65 - 80
if ( $hasil >= $bp[1] && $hasil <= $bp[2] )
{
$muBiasa = ($hasil >= $bp[2])? '0' : ($hasil - $bp[1]) / ($bp[2] - $bp[1]);
$muPuas = ($hasil - $bp[1]) / ($bp[2] - $bp[1]);
echo " muPuas " .$muPuas;
echo " muBiasa " .$muBiasa;
}
// antara 40 - 65
elseif ( $hasil >= $kb[1] && $hasil < $kb[2] )
{
$muKecewa = ($kb[2] - $hasil) / ($kb[2] - $kb[1]);
$muBiasa = ($hasil - $kb[1]) / ($kb[2] - $kb[1]);
echo "muKecewa " .$muKecewa;
echo "muBias " .$muBiasa;
}