3v4l.org

run code in 300+ PHP versions simultaneously
<?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);
Output for git.master, git.master_jit, rfc.property-hooks
0 Warning: Undefined array key ""Atleta"" in /in/5tWNj on line 55 Warning: Undefined array key ""Paquerador"" in /in/5tWNj on line 56 1 Warning: Undefined array key ""L\u00edder da turma"" in /in/5tWNj on line 51 Warning: Undefined array key ""Certinho"" in /in/5tWNj on line 52 2 Warning: Undefined array key ""T\u00edmido"" in /in/5tWNj on line 63 Warning: Undefined array key ""Desligado"" in /in/5tWNj on line 64 34 Warning: Undefined array key ""Bagunceiro"" in /in/5tWNj on line 56 5"\"Atleta\""

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
37.21 ms | 402 KiB | 8 Q