Skip to content

Instantly share code, notes, and snippets.

@acwoss
Created January 14, 2019 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acwoss/aaea2d99c784ef3c280c4fffe1ad847b to your computer and use it in GitHub Desktop.
Save acwoss/aaea2d99c784ef3c280c4fffe1ad847b to your computer and use it in GitHub Desktop.
ZanyRoastedAdmins created by acwoss - https://repl.it/@acwoss/ZanyRoastedAdmins
// 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