3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $answers = array('0' => '1', '1' => '0', '2' => '3', '3' => '2', '4' => '1', '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);
based on 2uF7j
Output for 5.3.0 - 7.2.0
0 Notice: Undefined index: "Atleta" in /in/5tWNj on line 55 Notice: Undefined index: "Paquerador" in /in/5tWNj on line 56 1 Notice: Undefined index: "L\u00edder da turma" in /in/5tWNj on line 51 Notice: Undefined index: "Certinho" in /in/5tWNj on line 52 2 Notice: Undefined index: "T\u00edmido" in /in/5tWNj on line 63 Notice: Undefined index: "Desligado" in /in/5tWNj on line 64 34 Notice: Undefined index: "Bagunceiro" in /in/5tWNj on line 56 5"\"Atleta\""
Output for 5.2.0 - 5.2.17
0 Notice: Undefined index: "Atleta" in /in/5tWNj on line 55 Notice: Undefined index: "Paquerador" in /in/5tWNj on line 56 1 Notice: Undefined index: "L\u00edder da turma" in /in/5tWNj on line 51 Notice: Undefined index: "Certinho" in /in/5tWNj on line 52 2 Notice: Undefined index: "T\u00edmido" in /in/5tWNj on line 63 Notice: Undefined index: "Desligado" in /in/5tWNj on line 64 34 Notice: Undefined index: "Bagunceiro" in /in/5tWNj on line 56 5"\"Atleta\""
Output for 5.0.0 - 5.1.6
0 Fatal error: Call to undefined function json_encode() in /in/5tWNj on line 55
Process exited with code 255.
Output for 4.4.5 - 4.4.9
0 Fatal error: Call to undefined function: json_encode() in /in/5tWNj on line 55
Process exited with code 255.
Output for 4.3.2 - 4.4.4
0 Fatal error: Call to undefined function: json_encode() in /in/5tWNj on line 55
Process exited with code 255.
Output for 4.3.0 - 4.3.1
0 Fatal error: Call to undefined function: json_encode() in /in/5tWNj on line 55