Jump to content

selecting the highest results


drtanz

Recommended Posts

Hi I have a questionnaire which the user submits and then the totals for the four variables are gathered according to the user's answer to the questions. At the end a report must be produced telling the user which style he prefers according to what variable/s are highest. I have the following code whose logic however breaks in the case when there is more than one highest value. how should i solve this? thanks

 

	$visual = $a1_3 + $a2_2 + $a3_1 + $a4_4 + $a5_4 + $a6_1 + $a7_1 + $a8_4 + $a9_4 + $a10_1;
    $auditory = $a1_2 + $a2_1 + $a3_4 + $a4_1 + $a5_1 + $a6_3 + $a7_3 + $a8_2 + $a9_2 + $a10_3;
    $kinesthetic = $a1_1 + $a2_4 + $a3_2 + $a4_3 + $a5_3 + $a6_2 + $a7_2 + $a8_3 + $a9_1 + $a10_4;
    $auditory_digital = $a1_4 + $a2_3 + $a3_3 + $a4_2 + $a5_2 + $a6_4 + $a7_4 + $a8_1 + $a9_3 + $a10_2;

echo "Visual score: $visual<br />";
echo "Auditory score: $auditory<br />";
echo "Kinesthetic score: $kinesthetic<br />";
echo "Auditory digital score: $auditory_digital<br />";    
   
If ($visual == $auditory && $visual == $auditory_digital && $visual == $kinesthetic) {
	echo ("Your preferred styles are Visual, Auditory, Kinesthetic and Auditory Digital");
}
elseif ($visual == $auditory && $visual == $kinesthetic) {
	echo ("Your preferred styles are Visual, Auditory and Kinesthetic");
}
elseif ($visual == $auditory && $visual == $auditory_digital) {
	echo ("Your preferred styles are Visual, Auditory and Auditory Digital");
}
elseif ($visual == $kinesthetic && $visual == $auditory_digital) {
	echo ("Your preferred styles are Visual, Kinesthetic and Auditory Digital");
}
elseif ($auditory == $kinesthetic && $auditory == $auditory_digital) {
	echo ("Your preferred styles are Auditory, Kinesthetic and Auditory Digital");
}
    elseif ($visual > $auditory && $visual > $kinesthetic && $visual > $auditory_digital){
        echo ("Your preferred style is Visual");
    }
    
    elseif  ($auditory > $visual  && $auditory > $kinesthetic && $auditory > $auditory_digital){
         echo ("Your preferred style is Auditory");
    }
    
    elseif ($kinesthetic > $visual && $kinesthetic > $auditory && $kinesthetic > $auditory_digital){
        echo ("Your preferred style is Kinesthetic");
    }   
    elseif ($auditory_digital > $visual && $auditory_digital > $auditory && $auditory_digital > $kinesthetic){
        echo ("Your preferred style is Auditory Digital");
    }
elseif ($visual == $auditory) {
	echo ("Your preferred styles are Visual and Auditory");
}
elseif ($visual == $kinesthetic) {
	echo ("Your preferred styles are Visual and Kinesthetic");
}
elseif ($visual == $auditory_digital) {
	echo ("Your preferred styles are Visual and Auditory Digital");
}
elseif ($auditory == $kinesthetic) {
	echo ("Your preferred styles are Auditory and Kinesthetic");
}
elseif ($auditory == $auditory_digital) {
	echo ("Your preferred styles are Auditory and Auditory Digital");
}
elseif ($kinesthetic == $auditory_digital) {
	echo ("Your preferred styles are Kinesthetic and Auditory Digital");
}	

Link to comment
https://forums.phpfreaks.com/topic/105845-selecting-the-highest-results/
Share on other sites

try

<?php
/**
* results in array
*/
$results = array (
             'V' => 20,
             'A' => 15,
             'K' => 20,
             'AD'=> 20
);
$max = max($results)  ;

$high = array_keys($results, $max);

echo 'you prefer ' . join (', ', $high);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.