Created
January 14, 2019 10:48
-
-
Save acwoss/aaea2d99c784ef3c280c4fffe1ad847b to your computer and use it in GitHub Desktop.
ZanyRoastedAdmins created by acwoss - https://repl.it/@acwoss/ZanyRoastedAdmins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://pt.stackoverflow.com/q/355941/5878 | |
$gabarito = '1;1;A|2;1;B|3;1;C|4;1;A|5;1;A|6;2;D|7;2;C|8;2;B|9;2;A|10;2;A'; | |
$materias = []; | |
foreach (explode('|', $gabarito) as $resposta) { | |
list($pergunta, $materia, $alternativa) = str_getcsv($resposta, ';'); | |
if ( ! array_key_exists($materia, $materias)) { | |
$materias[$materia] = []; | |
} | |
$materias[$materia][] = compact('pergunta', 'alternativa'); | |
} | |
echo json_encode($materias, JSON_PRETTY_PRINT); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment