<?php
$answers = array('0' => '0', '1' => '0', '2' => '0', '3' => '0', '4' => '0', '5' => '0');
// Name of result profiles
$p1 = "Líder da turma";
$p2 = "Valente";
$p3 = "Atleta";
$p4 = "Paquerador";
$p5 = "Certinho";
$p6 = "Bagunceiro";
$p7 = "Desligado";
$p8 = "Tímido";
// Weights of the questions answers
$a = array(array($p1, $p2),
array($p1, $p5),
array($p1, $p5),
array($p8, $p7),
array($p3, $p2),
array($p3, $p4));
$b = array(array($p3, $p4),
array($p6, $p3),
array($p3, $p4),
array($p6, $p2),
array($p8, $p6),
array($p8, $p7));
$c = array(array($p5, $p6),
array($p8, $p4),
array($p6, $p2),
array($p1, $p5),
array($p5, $p4),
array($p2, $p6));
$d = array(array($p7, $p8),
array($p2, $p7),
array($p8, $p7),
array($p3, $p4),
array($p7, $p1),
array($p5, $p1));
$arrayResults = array();
// Count the answers
foreach ($answers as $key => $value) {
echo $key;
$questionNumber = $key;
switch ($value) {
case '0':
$arrayResults[json_encode($a[$questionNumber][0])] += 1;
$arrayResults[json_encode($a[$questionNumber][1])] += 1;
break;
case '1':
$arrayResults[json_encode($b[$questionNumber][0])] += 1;
$arrayResults[json_encode($b[$questionNumber][1])] += 1;
break;
case '2':
$arrayResults[json_encode($c[$questionNumber][0])] += 1;
$arrayResults[json_encode($c[$questionNumber][1])] += 1;
break;
case '3':
$arrayResults[json_encode($d[$questionNumber][0])] += 1;
$arrayResults[json_encode($d[$questionNumber][1])] += 1;
break;
}
}
// Get the profile with the max points
$res = array_search(max($arrayResults), $arrayResults);
echo json_encode($res);
preferences:
35.32 ms | 402 KiB | 5 Q